502 Bad Gateway
This is an educational reference page about HTTP 502 Bad Gateway. The page itself is served as 200 OK so it can be indexed as HTTP documentation.
The server was acting as a gateway or proxy and received an invalid response from the upstream server.
What it means
HTTP 502 means a gateway or proxy received an invalid response from an upstream server.
Common causes
- The upstream application crashed, closed the connection, or returned malformed HTTP.
- A load balancer, CDN, reverse proxy, or API gateway could not use the upstream response.
- TLS, DNS, connection pool, or protocol mismatches between proxy and origin.
How to fix it
- Check proxy logs and upstream application logs for the same timestamp.
- Verify upstream health checks, ports, DNS, TLS, and timeout settings.
- Use retries carefully only when the request is safe to repeat.
Example response
HTTP/1.1 502 Bad Gateway
Content-Type: text/html
<h1>Bad Gateway</h1>
Developer notes
502 points at communication between servers. It usually is not caused by a malformed client request.