5xx Server Error

HTTP 502 Bad Gateway

The server, while acting as a gateway or proxy, received an invalid response from the upstream server. This often indicates a problem with the backend server, not the gateway itself.

Common Causes

  • Backend server is down or unreachable
  • Upstream server returned an invalid or malformed response
  • Network issues between the proxy/load balancer and backend
  • Backend server crashed or is being restarted

How to Fix

  1. 1Check if the backend server is running and healthy
  2. 2Review proxy/load balancer logs for connection errors
  3. 3Verify network connectivity between proxy and upstream
  4. 4Restart the backend server if it's unresponsive

Example

HTTP 502 Bad Gateway
GET /app HTTP/1.1 → Nginx (proxy)
→ Nginx tries to reach backend at port 3000
→ Backend is down
→ 502 Bad Gateway

Related Server Error Codes