Multi-server environment

Hey folks,

I run Kirby on several servers behind a load balancer. I have troubles with the media folder and images not being available on all servers. I’m guessing Kirby is generating the medias on one server, but then they are not available on the other ones.

Any idea on how I could do that? Without having to implement S3 storage or any other complicated solution?



You could serve all media from one server using the file::url() and file::version components.

But I don’t know how this would work with serving from different servers.

Thanks. Not sure I get it though. I would like the images to be served from a local folder on each server. .

The original images are deployed on each server. For instance my profile picture on my user account works on the first server that gets hit after deployment. But on my other server it looks like the folder in media is missing.

The files in the media folder are created on the fly, when the URL for a file is requested. So in theory, the files should be created in each media folder as soon as a particular server is hit.

I have never used Kirby in this way, so can’t really advise.

If that doesn’t work, maybe pre-generating all files before deploying could be an option?

@lukasbestle, @bastianallgeier?

@Michel_Vermeulen The issue in the setup you are describing is that one server creates the files in the media folder but another may be the one that will serve the media files depending on how the load balancer selects its backends. That will indeed not work with Kirby without modifications.

An alternative (which we use for the Kirby site and also our Kirby Demo) would be to use a pull-zone CDN for all media files that points to the media directory of one of your servers. You can then pre-generate all media files like we do it with the Kirby Demo, so that they are available for the CDN. If you use a CDN that has thumb capabilities (like KeyCDN, which we use), you can avoid pre-generating all thumbs on the server.

If you want a simple solution, you can configure your load balancer to always direct the requests of a specific user to the same backend. Then each backend can manage its own media folder and there won’t be issues like those you are describing.

BTW, what is the reason for the load balancer in your particular setup or which benefit do you see?

1 Like