// http 5xx · server error
HTTP 502 Bad Gateway
An upstream server returned an invalid response.
What HTTP 502 Bad Gateway means
502 Bad Gateway means a server acting as a proxy or gateway got an invalid response from the upstream server it relies on. The immediate server is fine; something behind it failed.
Which category is it?
502 is a 5xx code — Server error. 5xx means the server failed to fulfil an apparently valid request. It's the server's responsibility, not the caller's.
Common causes
- The upstream/origin server is down or crashed
- A misconfigured reverse proxy or load balancer
- The upstream returned a malformed response
How to fix it
- Check the health of the upstream service
- Verify proxy/load-balancer configuration
- Restart or redeploy the failing origin server
Example 502 response
HTTP/1.1 502 Bad Gateway
Server: nginx
Content-Type: text/html
<h1>502 Bad Gateway</h1>How to diagnose a 502
- Find which proxy or gateway returns the 502 (CDN, nginx, load balancer) and read its error log. It usually states the exact upstream failure, such as connection refused or invalid header.
- Check that the upstream application is running and listening on the port and address the proxy expects.
- Test the origin directly, bypassing the proxy, to separate an origin problem from a proxy configuration problem.
- Look for crashes or restarts around the time of the errors: a process that dies mid-request often produces a 502.
502 compared with similar codes
- 503: 503 is the server saying it is unavailable. 502 is a gateway reporting that the server behind it failed or returned garbage.
- 504: 504 is a timeout waiting for the upstream. 502 is an immediate invalid or failed response.
502 Bad Gateway: common questions
What does 502 Bad Gateway mean for a visitor?
The site's front-end server could not get a valid answer from the server behind it. It is usually temporary, so retrying after a minute often works.
How do I fix 502 errors on my own server?
Check that the application process is up, that the proxy points at the right upstream, and review proxy and application logs for the exact failure.