nginx refuses to start: `nginx: [emerg] host not found in upstream "backend:8080" in /etc/nginx/conf.d/app.conf:5`.
BeginnerTroubleshootingLoad balancers and reverse proxies
Answer
Likely causes → nginx resolves upstream hostnames at startup and fails if any don't resolve. In Docker Compose/Kubernetes this happens when nginx starts before the backend container/service exists, or the name is wrong (wrong network, wrong namespace).
Diagnose →
docker compose exec nginx getent hosts backend
docker network inspect <network> | grep -A3 backend
nginx -t
Fix → Put both containers on the same network and use the correct service name, add depends_on with a healthcheck condition, or use a variable with resolver 127.0.0.11 valid=10s; (Docker's embedded DNS) so resolution happens per request instead of at startup.
Prevent → Run nginx -t in CI against the target environment's names, and avoid hard startup dependencies between containers.
More on Load balancers and reverse proxies
nginx returns `502 Bad Gateway` and the error log says `connect() failed (111: Connection refused) while connecting to upstream`.Beginnernginx returns `504 Gateway Time-out` with `upstream timed out (110: Connection timed out) while reading response header from upstream`.BeginnerAn ALB target group shows all targets `unhealthy` with `Health checks failed with these codes: [404]`.BeginnerAn ALB returns sporadic `502`s, and access logs show `elb_status_code=502` with `target_status_code=-`. Load is low.Intermediatenginx logs `upstream prematurely closed connection while reading response header from upstream`.Intermediatenginx error log shows `no live upstreams while connecting to upstream` and every request gets 502.Intermediate