0

For local development, I have a suite of 5 sites.

Each site runs in its own php-fpm container.

All sites are served by a single nginx container, which contains .conf files for all the sites. They share ports, and are identified by server_name.

The issue

For the nginx container to start, all 5 php-fpm containers must be running already.

If one of them is not running, the nginx container will fail in a loop, with this in its logs:

2023-03-28 12:39:28 meq_nginx  | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
2023-03-28 12:39:28 meq_nginx  | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
2023-03-28 12:39:28 meq_nginx  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
2023-03-28 12:39:28 meq_nginx  | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
2023-03-28 12:39:28 meq_nginx  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
2023-03-28 12:39:28 meq_nginx  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
2023-03-28 12:39:28 meq_nginx  | /docker-entrypoint.sh: Configuration complete; ready for start up
2023-03-28 12:39:28 meq_nginx  | 2023/03/28 16:39:28 [emerg] 1#1: host not found in upstream "mysite" in /etc/nginx/conf.d/mysite.conf:29
2023-03-28 12:39:28 meq_nginx  | nginx: [emerg] host not found in upstream "mysite" in /etc/nginx/conf.d/mysite.conf:29

host not found in upstream "mysite" in /etc/nginx/conf.d/mysite.conf:29

refers to this configuration:

server {
    listen 443 ssl http2;

    location ~ ^/index\\.php(/|$) {
        fastcgi_pass mysite:9000;
...

...where "mysite" is the name of a php-fpm container that hasn't been started yet.

Desired behavior

  • Any site should work as long as its container is running.
  • If a container for one of the configured sites is not running, that should not prevent the nginx container from starting and serving other sites.
  • If a container for a site was started after nginx started, nginx should be able to serve it.
  • You should use docker-compose to create entire stack of services and manage relations between them. Also when defining upstreams in nginx you can change some default parameters like max_fails, fail_timeout, delayed_start or whether any backend is primary or backup one. Feel free to read nginx documentation here:http://nginx.org/en/docs/http/ngx_http_upstream_module.html – DevilaN Apr 04 '23 at 07:24

0 Answers0