Bad Gateway
The server, acting as a gateway or proxy, received an invalid response from an upstream server.
Root Cause
The upstream server (application server, API, microservice) is down, crashed, or returned an invalid response.
How to Fix
Check the upstream server's health and logs. Verify the proxy configuration. Implement health checks and circuit breakers.
Quick Summary
502 means a proxy or gateway received an invalid response from an upstream server. Check the upstream service health. Common in Nginx/load balancer setups when the app server is down.
Key Takeaways
- The proxy is working but the upstream server is not responding correctly
- Check the upstream server logs, not the proxy logs
- Implement health checks so the load balancer can route around failed instances
- Circuit breakers prevent cascading failures when upstream services are down
When to use it
- App server crashed behind Nginx
- Microservice is down
- Upstream API returned an invalid response
Common Mistakes
- Checking the proxy logs instead of the upstream server logs
- Not implementing health checks, the load balancer keeps sending traffic to failed instances
502 Bad Gateway, Frequently Asked
What is the difference between 502 and 503?
502 Bad Gateway: the upstream server returned an invalid response. 503 Service Unavailable: the server is temporarily unable to handle requests (overloaded or in maintenance).
Still having issues?
Check your network logs or use our developer tools to inspect headers, decode tokens, or validate your requests.