HTTP 502 Bad Gateway

The server, while acting as a gateway or proxy, received an invalid response from the upstream server.

5xx Server Error

502

Bad Gateway

Description

The 502 Bad Gateway status code indicates that the server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request. This typically means the upstream server sent a response that the gateway could not understand or parse. It does not necessarily mean the upstream server is down; the response could be malformed, incomplete, or use an unexpected protocol. Common scenarios include reverse proxy servers (like Nginx) receiving errors from application servers (like Node.js, Python, or PHP backends).

When Is It Used?

Commonly encountered with reverse proxies (Nginx, HAProxy), load balancers, CDNs, and API gateways when the upstream application server crashes, returns a malformed response, or uses an incompatible protocol. Also seen when the upstream server closes the connection unexpectedly.

Example Response

HTTP/1.1 502 Bad Gateway
Content-Type: text/html

<h1>502 Bad Gateway</h1>
<p>The server received an invalid response from the upstream server.</p>

Look Up Any Status Code

Browse all status codes