Error Codes Wiki

HTTP 502 Bad Gateway — What It Means & How to Fix It

Critical5xx server error

Overview

The HTTP 502 Bad Gateway status code indicates a server acting as a gateway or proxy received an invalid response from an upstream server.

Key Details

  • This error occurs in multi-server architectures where a proxy or load balancer forwards requests.
  • The gateway or proxy server itself is working, but the upstream server is not responding correctly.
  • Common with nginx, Apache reverse proxies, CDNs, and load balancers.
  • The upstream server may be down, overloaded, or returning malformed responses.
  • It is often a transient error that resolves on its own.

Common Causes

  • The upstream server is down or not responding.
  • The upstream server returned a malformed or invalid response.
  • Network issues between the proxy and the upstream server.
  • The upstream server is overloaded and cannot handle the request.

Steps

  1. 1Retry the request after a short wait as it is often transient.
  2. 2Check if the upstream server is running and healthy.
  3. 3Review proxy and load balancer logs for detailed error information.
  4. 4Verify network connectivity between the proxy and upstream server.
  5. 5Check upstream server resource utilization (CPU, memory, connections).

Tags

httpserver-errorgatewayproxyupstream

Related Items

More in 5xx Server Error

Frequently Asked Questions

It means a server acting as a proxy or gateway received an invalid response from the upstream server it was forwarding the request to.