User Tools

Site Tools


wiki:avoid_upstream_not_found_nginx_using_only_one_server

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

  • nginx/1.22.1

See also

References

wiki/avoid_upstream_not_found_nginx_using_only_one_server.txt · Last modified: 2023/04/18 12:34 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki