Setup nginx not to crash if host in upstream is not found with upstream group

I have read question 32845674 (and many others) and the answers to it, but I don't understand how to apply the solution shown to my case: In my nginx configuration, upstreams are used specifically for grouping servers (which are multiple docker containers that differ in numbers at the end, e.g. portal_frontend_dev_frontend_1, portal_frontend_dev_frontend_2 etc.) Also, nginx (as an another docker container) serves as a balancer on one physical server between three environments represented by different containers - dev, staging and production, each of them is represented by several containers of the same name and accepts requests through nginx. Of course, I don't want to find that nginx crashes and access to all environments (including production) has disappeared cause, for example, the frontend_dev containers have fallen when I restart it (e.g. to update config). So how do I need use variables with upstreams?

P.S. simply adding a 127.0.0.11 resolver doesn't help - if any of the upstream containers is not running - nginx won't start with the error

[emerg] host not found in upstream "portal_frontend_dev_frontend_1:8080" in /etc/nginx/conf.d/staging.conf:18

Additionally: do not be confused by the fact that the dev is in the staging config - I have a separation between dev and staging occurs at the locations, because I don't have a third domain name yet. This fact is immutable and doesn't depend on me.

That's my /etc/nginx/conf.d/staging.conf

upstream portal_frontend_stage {
    server portal_frontend_stage_frontend_1:8080 max_conns=1 max_fails=0;
    server portal_frontend_stage_frontend_2:8080 max_conns=1 max_fails=0;
}

upstream portal_frontend_dev {
    server portal_frontend_dev_frontend_1:8080 max_conns=1 max_fails=0;
    server portal_frontend_dev_frontend_2:8080 max_conns=1 max_fails=0;
}
upstream portal_backend_dev {
    server portal_backend_dev_backend_1:80 max_conns=1 max_fails=0;
    server portal_backend_dev_backend_2:80 max_conns=1 max_fails=0;
}
upstream portal_backend_stage {
    server portal_backend_stage_backend_1:80 max_conns=1 max_fails=0;
    server portal_backend_stage_backend_2:80 max_conns=1 max_fails=0;
}

server {
    listen 80 default_server;
    server_name "example.staging.com";
    resolver 127.0.0.11;


    include conf.d/logs.inc;
    include conf.d/cloudflare.inc;
    include conf.d/proxy.inc;
    include conf.d/develop.inc;
    include conf.d/stage.inc;
    include conf.d/google-analytics.inc;
}

Upvotes: 1

Views: 576

Answers (0)

Related Questions