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.
Specification
RFC 9110 §15.6.3
Examples
HTTP/1.1 502 Bad Gateway
Content-Type: application/json
{"error":"Bad Gateway"}res.status(502).json({ error: "Bad Gateway" });w.WriteHeader(http.StatusBadGateway)
return jsonify({"error": "Bad Gateway"}), 502Related status codes
Internal Server Error
A generic error message given when an unexpected condition was encountered on the server.
Service Unavailable
The server is currently unable to handle the request due to temporary overloading or maintenance.
Gateway Timeout
The server, acting as a gateway or proxy, did not receive a response from the upstream server in time.