Cloudflare 502 Bad Gateway and 52x errors
A 5xx from Cloudflare, such as a Cloudflare 502 Bad Gateway, means one of two things. Either your Worker or Pages Function threw an error, or Cloudflare could not get a good answer from your origin server. Cloudflare reports origin problems with its own 520 to 526 codes. It charts both kinds, but its error-rate alerts are for Enterprise plans only.
Cloudflare 502 Bad Gateway
A 502 page with Cloudflare’s branding means the problem was inside Cloudflare, and usually clears by itself. A 502 without it came from your origin, passed through unchanged: the app behind it failed. See 502 Bad Gateway for how to trace it.
Cloudflare’s 52x codes
| Code | What happened |
|---|---|
| 520 | The origin returned an empty, unknown or unexpected response |
| 521 | The origin refused the connection: the web server is down or blocks Cloudflare |
| 522 | The connection to the origin timed out |
| 523 | The origin is unreachable: a DNS or routing problem |
| 524 | The origin accepted the connection but did not answer in time |
| 525 | The TLS handshake between Cloudflare and the origin failed |
| 526 | The origin’s certificate is not valid |
Where Cloudflare shows them
Zone analytics break traffic down by status code. Workers and Pages Functions show requests and errors per script in their metrics.
What Cloudflare does not alert on below Enterprise
Cloudflare’s Origin Error Rate and Advanced Error Rate notifications are available on Enterprise plans only. On other plans, a Worker or an origin can fail a share of its requests without a notification.