/errors/nginx/host-not-found-in-upstream
nginx: [emerg] host not found in upstream "backend"
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · nginx version: nginx/1.30.6updated 2026-10-20
- tool
- nginx
- exit code
- 1
- versions
- nginx 1.x
- os
- any
nginx resolves every hostname in proxy_pass and upstream { server … } once, when it loads the configuration. If a name does not resolve at that moment, nginx -t, start and reload all fail with [emerg] host not found in upstream "backend-app". This happens a lot with containers, where the backend's DNS name exists only while that container is running.
Reproduce it
mkdir -p logs temp
cat > nginx.conf <<'EOF'
pid logs/nginx.pid;
events {}
http {
server {
listen 127.0.0.1:8080;
location / {
proxy_pass http://backend-app:3000;
}
}
}
EOF
# -p . uses this directory as the prefix; sed drops the log timestamp and process id
nginx -p . -c nginx.conf -e stderr -t 2>&1 | sed -E 's/^[0-9/]+ [0-9:]+ \[([a-z]+)\] [0-9#]+: /[\1] /'
exit "${PIPESTATUS[0]}"Output · exit 1
[emerg] host not found in upstream "backend-app" in ./nginx.conf:7 nginx: configuration file ./nginx.conf test failed
Fix: make the name resolvable
getent hosts backend-app # from inside the nginx container: docker compose exec nginx getent hosts backend-appservices:
nginx:
image: nginx:1.29
depends_on: [backend-app]
backend-app:
image: example/app:1.0Services in the same Compose project share a default network, where each service name is a DNS name.
Fix: resolve at request time
With a variable in proxy_pass, nginx looks the name up per request through the resolver (Docker's embedded DNS is 127.0.0.11), so it starts even when the backend is down and follows IP changes:
resolver 127.0.0.11 valid=10s;
location / {
set $backend http://backend-app:3000;
proxy_pass $backend;
}Sources
Related pages
errors · nginxnginx: "proxy_pass" cannot have URI part in location given by regular expressionnginx rejects proxy_pass http://host/path/ inside a regex location, named location, if or limit_except. Remove the URI part and change the path with rewrite.commands · nginxnginx -t: test the configuration before reloadingnginx -t checks the configuration syntax and the files it references without touching the running server; nginx -T also prints the full merged config.glossary · nginxWhat is a reverse proxy?A reverse proxy is a server in front of your applications that receives client requests and forwards them to backends, adding TLS, caching and balancing.