HTTP 502 Bad Gateway — Upstream Server Failure Analysis
Critical5xx server error
Overview
Deep dive into HTTP 502 Bad Gateway: diagnosing upstream server failures, proxy misconfigurations, and backend crashes with advanced troubleshooting techniques.
Key Details
- 502 means the proxy or gateway received an invalid response from the upstream server
- The error is between the proxy/load balancer and the backend — not the client's fault
- Common with Nginx, Apache reverse proxy, AWS ALB, Cloudflare, and other CDNs
- Backend application crash, timeout, or malformed response all cause 502
- Intermittent 502s often indicate backend resource exhaustion or health check failures
Common Causes
- Backend application crashed or is not running on the expected port
- Upstream server returned a malformed HTTP response
- Backend processing time exceeded proxy timeout settings
- DNS resolution failure for the upstream server
- SSL/TLS handshake failure between proxy and backend
- Backend running out of memory, connections, or file descriptors
Steps
- 1Check backend application logs for crashes, OOM kills, or exceptions
- 2Verify the backend is running: curl -v http://localhost:BACKEND_PORT directly
- 3Check Nginx error log: tail -f /var/log/nginx/error.log for upstream connection details
- 4Increase proxy timeout: proxy_read_timeout 300s; in Nginx for slow backends
- 5Verify DNS resolution: dig upstream-hostname and ensure it resolves correctly
- 6Check backend health: systemctl status your-app and journalctl -u your-app for errors
Tags
http502bad-gatewayproxyupstream
More in 5xx Server Error
http-500-internal-server-errorHTTP 500 Internal Server Error — What It Means & How to Fix It
Criticalhttp-501-not-implementedHTTP 501 Not Implemented — What It Means & How to Fix It
Criticalhttp-502-bad-gatewayHTTP 502 Bad Gateway — What It Means & How to Fix It
Criticalhttp-503-service-unavailableHTTP 503 Service Unavailable — What It Means & How to Fix It
Criticalhttp-504-gateway-timeoutHTTP 504 Gateway Timeout — What It Means & How to Fix It
Criticalhttp-505-http-version-not-supportedHTTP 505 HTTP Version Not Supported — What It Means & How to Fix It
CriticalFrequently Asked Questions
No. 502 is always a server-side issue between the proxy/gateway and the upstream backend server.