User Tools

Site Tools


wiki:avoid_upstream_not_found_nginx_using_only_one_server

This is an old revision of the document!


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;
  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).

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.1680180771.txt.gz · Last modified: 2023/03/30 14:52 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