The basic idea is to move application servers into LXC containers while keeping the HTTP server part (which is also responsible for hosting static files) on the host system.
Normally an incoming request would be handled by an HTTP server on the host as well as by an HTTP server on the virtualized client:
|
|
I’m configuring the host HTTP server to directly communicate with the app worker, thus:
|
|
This removes one layer of indirection and simplifies HTTP server configuration (think maximum file-sizes which would have to be adopted for each web server). This is also possible als LXC containers are located within the host filesystem (i.e. /var/lib/lxc/<container name>/rootfs
): the host web server can thus directly access static files without even invocing the guest container in the first place.
One downfall for my (converted) setups was that the Unix sockets within the containers were located within /var/run
by default – this was located within an per-container tmpfs (virtual in-memory filesystem). This makes this file invisible from outside the container. The quick’n’dirty solution for this was to move the unix domain socket into the containers root filesystem: this will be available from outside the container.
Some example configurations:
ttrss
nginx configuration:
|
|
Notice the fastcgi_param
entry: here the requested PHP filename is rewritten so that the in-container path (which will be forwarded to the PHP-FPM application server) does not contain the LXC container prefix (/var/lib/lxc/ttrss/rootfs
).
seafile
nginx configuration:
|
|
There’s actually nothing noteworthy here.
gitlab
I’m using gitlab not with a domainname of its own but am “mouting” it at /gitlab. This allows me to reuse the same SSL certificate. The corresponding nginx configuration:
|
|