start nginx despite missing upstream

You can setup an upstream server with backup option, then won't be normally hit.

upstream cache {
    server 192.168.1.2:8080 fail_timeout=5s max_fails=3;
    server 127.0.0.1:82 backup;
}

location / {
    proxy_pass http://cache;
    proxy_next_upstream error http_502;
}

Make sure your primary cache server return consistent error, so that the failure is quickly detected.


Nice trick (not only for docker deployments) is mentioned at https://sandro-keil.de/blog/let-nginx-start-if-upstream-host-is-unavailable-or-down/

All kudos to Sandro Keil -- just for reference -- basically he defines a resolver with timeout and all upstream servers through variables:

server {
    # this is the internal Docker DNS, cache only for 30s
    resolver 127.0.0.11 valid=30s;

    location ^~ /api/ {
        # other config entries omitted for breavity

        set $upstream api.awesome.com:9000;

        # nginx will now start if host is not reachable
        fastcgi_pass    $upstream; 
        fastcgi_index   index.php;
    }
}

I use this solution for local development (allows me to start only subset of services with single nginx config) and also at production.