502 Bad Gateway
A proxy or load balancer got an invalid response from the upstream server it was relaying to. The failure is behind the thing that answered you.
At a glance
- Status code
- 502 Bad Gateway
- Class
- 5xx, server error, the request looked fine and the server failed
- Defined in
- RFC 9110
- Cacheable by default
- by explicit headers only
- Response body
- Usually a generic gateway error page.
In detail
The gateway reached the origin and what came back was unusable: a connection reset, a truncated response, malformed headers, or a process that died mid-request.
Only an intermediary should produce 502. An application server returning 502 about itself is reporting on a dependency, and 503 usually fits that better.
Check whether the origin process is running, whether it crashed on this request, and whether the gateway timeout is shorter than the origin's own response time.
Examples
HTTP/1.1 502 Bad Gateway
Content-Type: text/html
Retry-After: 5
<h1>Bad gateway</h1>Things that catch people out
- 502 immediately after a deploy usually means the gateway started routing before the new process was listening. Health checks fix this, delays do not.
- A 502 on large responses only is often a buffer limit on the proxy rather than a fault in the application.
Try it: HTTP Request Builder
Build a request with any method, headers and body, send it, and read the status line the server returns.
HTTP Request Builder
LOCAL · Browser-OnlyBuild and test HTTP requests with custom headers and body
Authentication
Headers
Generate Code
curl -X GET 'https://api.example.com/endpoint' \
-H 'Content-Type: application/json'Showing a sample URL. Enter your endpoint above to update the snippet.
Related HTTP status codes
All http status codes →503 Service Unavailable
The server is temporarily unable to handle the request, because it is overloaded or deliberately down for maintenance. The condition is expected to clear.
504 Gateway Timeout
A proxy gave up waiting for the upstream server to answer. The upstream may still be working on the request.
500 Internal Server Error
The server hit an unexpected condition and cannot say anything more specific. It is the catch-all for unhandled exceptions.
505 HTTP Version Not Supported
The server refuses the major HTTP version used in the request line.
506 Variant Also Negotiates
A server configuration error in transparent content negotiation: a chosen variant is itself configured to negotiate, creating a loop.
507 Insufficient Storage
The server cannot store the representation needed to complete the request, because it is out of space.
Tools for this
- HTTP Request Builder Free online HTTP request builder - build and test HTTP requests with custom headers and body
- HTTP Headers Checker Free online HTTP headers checker - view HTTP response headers for any URL