HTTP 502 Bad Gateway — What It Means

What HTTP status code 502 Bad Gateway means, when servers return it, and how to handle it correctly.

Published September 26, 2026

HTTP 502 Bad Gateway means a gateway or proxy received an invalid response from the upstream server. The problem is usually the backend app crashing or being unreachable.

What it means

Check that the upstream is running and listening on the expected address.

Common causes: Backend app crashed or not started; Wrong upstream port or socket; Upstream returning garbage or timing out.

On the wire

GET / HTTP/1.1
HTTP/1.1 502 Bad Gateway
Server: nginx
A typical 502 exchange.

Practical examples

Test it from the shell

curl -i https://example.com/path   # look for HTTP 502

Handling 502 in code or config

tail -f /var/log/nginx/error.log

How to fix it

Restart or fix the backend; Check proxy_pass or FastCGI address; Read the error logs.

1. Reproduce: curl -i <url>
2. Confirm the status is 502
3. Apply the fix above and re-test

Common mistakes

  • Restart or fix the backend
  • Check proxy_pass or FastCGI address
  • Ignoring the response headers that explain the details.

Key takeaways

  • 502 means Bad Gateway.
  • HTTP 502 Bad Gateway means a gateway or proxy received an invalid response from the upstream server.
  • Read the response headers and logs for the exact cause.

FAQ

502 vs 504?

502 is an invalid response; 504 is no response in time.

Is 502 a client or server error?

It is a server error status code, in the 5xx class.

More HTTP articles