Table of Contents

,

Avoid upstream not found in nginx when using only one upstream server

If you have a situation where there is only one upstream that you need to proxy_pass, use a variable in the proxy_pass directive, e.g.

server {
  listen 80;
  resolver 127.0.0.11 valid=30s; # docker's resolver
  set $target "http://target-host:3005";  # variable definition
  location / { 
    proxy_pass $target; 
  }
}

This will not error out if the target-host is not available (for example in some Docker setup).

resolver is probably needed even when the target host is not a docker container

The following example however will give you an error if the target-host can not be resolved:

upstream target {
    server target-host:3005;
}
 
server {
  listen 80;
 
  location / { proxy_pass $target; }
}

Tested on

See also

References