{{tag>nginx docker}}
====== 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 ======
* [[wiki:nginx_troubleshooting|Nginx troubleshooting]]
====== References ======
* https://stackoverflow.com/questions/32845674/setup-nginx-not-to-crash-if-host-in-upstream-is-not-found