An ALB target group shows all targets `unhealthy` with `Health checks failed with these codes: [404]`.
BeginnerTroubleshootingLoad balancers and reverse proxies
Answer
Likely causes → The health check path doesn't exist on the app (default is /), the app requires a specific Host header, or a framework redirects/serves 404 for unknown hosts (the ALB sends the target IP as Host).
Diagnose →
aws elbv2 describe-target-health --target-group-arn <tg-arn>
aws elbv2 describe-target-groups --target-group-arns <tg-arn> \
--query 'TargetGroups[0].[HealthCheckPath,HealthCheckPort,Matcher]'
curl -i http://<target-private-ip>:<port>/health # from a host in the VPC
Fix → Point the health check at a real lightweight endpoint (/healthz) and set the matcher (200 or 200-399). Allow the app to answer health checks for any Host (e.g. Django ALLOWED_HOSTS, Rails config.hosts).
Prevent → Ship a dedicated health endpoint in every service template and test it in CI.
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 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.IntermediateAn NLB shows all targets healthy, but clients from the internet time out connecting through it.Intermediate