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

  1. If you can use a static IP then just use that, it’ll startup and just return 503‘s if it doesn’t respond.

  2. Use the resolver directive to point to something that can resolve the host, regardless if it’s currently up or not.

  3. Resolve it at the location level, if you can’t do the above (this will allow Nginx to start/run):

     location /foo {
       resolver 127.0.0.1 valid=30s;
       # or some other DNS (your company's internal DNS server)
       #resolver 8.8.8.8 valid=30s;
       set $upstream_foo foo;
       proxy_pass http://$upstream_foo:80;
     }
    
     location /bar {
       resolver 127.0.0.1 valid=30s;
       # or some other DNS (your company's internal DNS server)
       #resolver 8.8.8.8 valid=30s;
       set $upstream_bar foo;
       proxy_pass http://$upstream_bar:80;
     }
    

Leave a Comment