← All notes
TECHNICAL GUIDE · 2026-11-13

Tracing Nginx 502 and 504 Gateway Errors

Follow a failing request through the reverse proxy to DNS, upstream reachability, application logs and resource signals.

NginxHTTPLinuxTroubleshooting

Understand the failure boundary

A 502 Bad Gateway typically means the proxy received an invalid or failed response from an upstream. A 504 Gateway Timeout means it waited too long for a response. The HTTP status narrows the search, but it does not tell you the root cause by itself.

Validate the Nginx layer

nginx -t
# If Nginx runs in Docker:
docker exec nginx-proxy nginx -t

Review the intended server_name, upstream target, expected port and error log near the failing request. Use nginx -T only when configuration disclosure is acceptable in your environment.

Reach the upstream from the proxy network

On a Docker host with a user-defined network, test the same hostname and port Nginx uses:

docker exec nginx-proxy wget -S -O /dev/null http://app:3000/health

If the app responds directly but the public route does not, investigate host matching, proxy configuration and tunnel routing. If it times out inside the Docker network, inspect the upstream process, readiness, resource limits and runtime logs.

Correlate with service state

docker ps --all
docker logs --tail 100 app
curl -I https://example.com/health

Avoid changing timeouts before checking whether the application is actually healthy. A higher proxy timeout cannot fix a crashed process or a broken service dependency.

Close the loop

After an approved fix, verify the hostname and original path from outside, confirm the app’s functional response, and observe recent error logs for recurrence.