Skip to content
Advertisement

how to setup a single nginx server with multiple php-fpm docker containers

Nginx is running on my server (not a docker image) to proxy the subdomain requests to my docker containers.

Having an additional nginx container for each image works well as follows:

docker-compose.yml

JavaScript

site.conf

JavaScript

/etc/nginx/sites-available/dev.domain.co.uk

JavaScript

But seems wasteful to have an additional instance of nginx for each php site.

How can I route the server instance of nginx directly to each php:fpm container?

note: the docker ‘code-network’ gets renamed appname-code-network upon docker-compose up -d

Advertisement

Answer

Figured this out.

In the nginx server conf, the root is the location to the code on the server host i.e. /home/user/CODE/site

the fastcgi_param is the location of the code on the Docker container, (/app) as defined in docker-compose.yml

JavaScript

You also need to pass to the docker container host ip:

JavaScript

As discovered by hostname -I, when using bash on the container.

I’m yet to discover how to use the container hostname instead

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement