Skip to content

/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

bash
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

bash
getent hosts backend-app          # from inside the nginx container: docker compose exec nginx getent hosts backend-app
compose.yaml
services:
  nginx:
    image: nginx:1.29
    depends_on: [backend-app]
  backend-app:
    image: example/app:1.0

Services 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:

nginx
resolver 127.0.0.11 valid=10s;
location / {
    set $backend http://backend-app:3000;
    proxy_pass $backend;
}

Sources