Toolman

HTTP 502 — Bad Gateway

5xx Server Error

What it means

A server acting as a proxy got an invalid response from the upstream server.

What to do about it

The application behind the proxy is down, crashed, or returned garbage. Check that the app is running and listening on the port nginx or the load balancer expects.

Where it sits

502 belongs to the 5xx family: The server failed to fulfil an apparently valid request. The fix is on the server side.

HTTP/1.1 502 Bad Gateway

Checking it yourself

# see the status code and headers only
curl -sI https://example.com/path

# follow redirects and print each hop
curl -sIL -o /dev/null -w "%{http_code} %{url_effective}\n" https://example.com/path

# JavaScript
const r = await fetch(url);
console.log(r.status, r.statusText);

How this code behaves

Cacheable by defaultNo — caches must not store this response unless explicit cache headers permit it.
Safe to retryYes, with backoff. This is a transient condition; retrying the same request is reasonable.
Effect on search indexingRepeated server errors reduce crawl rate and eventually drop pages from the index.

Returning 502 correctly

# nginx
return 502;

# Express
res.status(502).json({ error: 'Bad Gateway' });

# Go
w.WriteHeader(502)

# Python (Flask)
return jsonify(error='Bad Gateway'), 502;

Frequently asked questions

What does HTTP 502 mean?

A server acting as a proxy got an invalid response from the upstream server.

How do I fix a 502 error?

The application behind the proxy is down, crashed, or returned garbage. Check that the app is running and listening on the port nginx or the load balancer expects.

Is 502 a client or server problem?

A server problem. The request was valid; the server failed to fulfil it. Nothing the client changes will help.

Other 5xx codes

All HTTP status codes