nginx: [emerg] host not found in upstream
There are several answers to be found on the Internet in relation to this problem, but somehow none of them worked for my case.
I run the nginx docker command from command line like this:
docker run --name nginx -p 80:80 \
-v ${HOME}/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \
-it --rm nginx:1.13
In my nginx.conf file I had my upstream defined like this:
upstream authenticator {
server myserver;
}
Where myserver was a separate internal host.
The suggested solution is to add a resolver directive to the config with the ip of the nameserver.
resolver 1.1.1.1;
upstream authenticator {
server myserver;
}
That didn't work either.After investigating the containers /etc/resolve.conf file I found that it points to 8.8.8.8 that is the google dns.
Because myserver is in fact an internal server it wouldn't resolve of course and seems that nginx docker by default won't pick up my resolver ip to resolve the host name.
I concluded that the solution was to add a switch to the docker command that pointed docker to my internal dns and that worked.
docker run --name nginx -p 80:80 \
-v ${HOME}/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \
-it --rm --dns 1.1.1.1 nginx:1.13
References:
- Docker Nginx stopped: [emerg] 1#1: host not found in upstream
- nginx: configuration file /etc/nginx/nginx.conf test failed (host not found in upstream)
- setup nginx not to crash if host in upstream is not found
- Nginx official upstream documentation
- Docker dns documentation
Comments
Post a Comment