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>Related Status Codes
500
Internal Server Error
The server encountered an unexpected condition that prevented it from fulfilling the request.
503
Service Unavailable
The server is currently unable to handle the request due to temporary overload or maintenance.
504
Gateway Timeout
The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server.