DevKits
502

Bad Gateway

5xx Server Error

Last updated:

The server, acting as a gateway or proxy, received an invalid response from the upstream server.

Description

The classic 'my origin server is broken' error from CDNs and load balancers. Common causes: upstream returned malformed HTTP, or the upstream process crashed mid-response.

When to use

Automatic on most proxies (nginx, Cloudflare, ALB) when upstream fails. You rarely emit 502 from application code.

Also searched as

Developers commonly search for 502 using phrases like 502 bad gateway · 502 error · http 502 · 502 bad gateway fix · 502 bad gateway meaning · bad gateway error · 502 status code. All refer to the same HTTP 502 Bad Gateway response.

Specification

RFC 9110 §15.6.3

Examples

HTTP response
HTTP/1.1 502 Bad Gateway
Content-Type: application/json

{"error":"Bad Gateway"}
Node.js (Express)
res.status(502).json({ error: "Bad Gateway" });
Go (net/http)
w.WriteHeader(http.StatusBadGateway)
Python (Flask)
return jsonify({"error": "Bad Gateway"}), 502

Debug 502 with these tools

Related status codes

All 5xx codes