The HTTP 502 (Bad Gateway) status code means that a server acting as a gateway or proxy received an invalid response from an inbound server it accessed while trying to fulfill the request, according to RFC 9110, the IETF standard that defines HTTP semantics. In the words of Section 15.6.3 of RFC 9110, "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."
Who sends a 502
Section 3.7 of RFC 9110 names three common forms of intermediary: proxy, gateway and tunnel. It describes a gateway, also known as a reverse proxy, as an intermediary that acts as an origin server for the outbound connection but forwards requests inbound to another server or servers, and says gateways are often used for caching, to encapsulate legacy or untrusted services, and to partition or load balance HTTP services across multiple machines. A proxy is chosen by the client, usually through local configuration, and is often used to group an organization's requests through a common intermediary for security, annotation or shared caching.
The same section defines the direction words the 502 definition relies on: inbound means toward the origin server, and outbound means toward the user agent.
How 502 compares with nearby codes
RFC 9110 gives each server error its own condition, and the gateway codes differ by what the intermediary got back.
| Code | Name | What RFC 9110 says it means |
|---|---|---|
| 500 | Internal Server Error | An unexpected condition prevented the server from fulfilling the request |
| 502 | Bad Gateway | A gateway or proxy received an invalid response from an inbound server |
| 503 | Service Unavailable | The server cannot handle the request now because of a temporary overload or scheduled maintenance |
| 504 | Gateway Timeout | A gateway or proxy did not receive a timely response from an upstream server |