Cloud · 2026-11-25 · 9 min

Cloudflare 5xx: Edge, Origin and Firewall

Cloudflare 500, 520 and 522 look alike but come from different places. Separate edge, origin, DNS, TLS and firewall faults with checks that produce evidence.

By Open Error Codes EditorialReviewed 2026-11-25

A Cloudflare 5xx page is not one error. It is a family of failures that occur at different points between the visitor and your application: at the edge, on the path to the origin, inside the origin's TLS stack, or in the application itself. The code tells you which point, and the response headers tell you who wrote the page. This guide separates 500, 520 and 522, then walks the origin DNS, TLS, firewall and HTTP checks that produce evidence instead of guesses.

Who generated the page?

Cloudflare adds a cf-ray header to proxied responses, so its presence proves the request passed through the edge. It does not prove the edge wrote the error. Those are different questions, and confusing them is the usual reason a 5xx investigation stalls.

The practical split is this. A 500 is an HTTP status the origin itself returned, or that a Cloudflare Worker, Page Rule or Transform Rule produced at the edge. A 520 is generated by Cloudflare when the origin's reply could not be parsed as HTTP at all. A 522 is generated by Cloudflare when no usable TCP connection or first byte arrived from the origin. In the last two cases the origin may have logged nothing, because the request never became valid HTTP there.

RFC 9110 groups 5xx as the server's own error class — the server is aware that it has erred or cannot perform the method — and defines 500 as an unexpected condition that prevented it from fulfilling the request. Codes 520 and 522 are Cloudflare-specific: they are not in the IANA HTTP status registry, so treat them as diagnostics about the edge-to-origin hop rather than as standard HTTP semantics.

Read the response before touching the dashboard

The first command should capture the status line, the full header set and the TLS details in one pass. Look at server, cf-ray, cf-cache-status and the error page body.

# 1. Status line and headers, edge included
curl -sSI https://www.example.com/ | head -n 30

# 2. Verbose handshake with request headers, useful for 520 and 522
curl -vI https://www.example.com/ 2>&1 | sed -n '1,45p'

# 3. Which address does the proxied name resolve to?
dig +short www.example.com
dig +short www.example.com @1.1.1.1

# 4. Reach the origin directly, bypassing the edge
curl -vI --resolve www.example.com:443:203.0.113.10 https://www.example.com/

# 5. TLS handshake against the origin, not the edge
openssl s_client -connect 203.0.113.10:443 -servername www.example.com -brief </dev/null

Replace the documentation address 203.0.113.10 with your origin's address. Command 4 is the most useful test in the list: if the origin answers 200 directly but visitors receive 520 or 522, the fault is on the edge-to-origin hop — firewall, allowlist, TLS mode or protocol handling — not in the application code.

The three codes side by side

CodeGenerated byImmediate meaningTypical evidence
500Origin app, or a Worker or rule at the edgeA server reached the request and failedOrigin access log shows 500; stack trace or exception
520Edge, after an unparseable origin replyOrigin sent an empty or malformed responseNo status line in origin logs; oversized headers
522Edge, before any HTTP response existedTCP connect or first byte timed outNo request in origin logs; SYN dropped or port closed

Origin DNS: the address Cloudflare dials

For a proxied record, visitors resolve to Cloudflare, and Cloudflare resolves the origin separately. If the DNS record in the dashboard points at an address the server no longer holds — after a migration, a rebuilt instance, or an IP change by the hosting provider — a 522 is the predictable result, because the edge keeps dialling a host that no longer answers there.

Compare three values: the address in the Cloudflare DNS app, the address the origin server reports locally, and the address that answers on port 443 from outside. The DNS reference covers record types and resolution order; what matters here is that all three agree. Also confirm whether the record is proxied or DNS-only, and whether an Origin Rule rewrites the host or port to something that does not resolve: a host name pointing at a reserved address such as 100:: yields a 522 rather than a useful response.

TLS mode and the certificate the origin presents

The SSL/TLS mode decides how the edge talks to the origin. Flexible means HTTP to the origin: the edge terminates TLS and the origin never sees HTTPS. Full means HTTPS to the origin without validating the certificate. Full (strict) validates it against a trusted chain or a Cloudflare Origin CA certificate. A certificate that is expired, self-signed or issued for another host name fails under Full (strict), and the handshake failure can surface as a 5xx rather than a certificate warning in the browser.

Command 5 above shows exactly what the origin presents: the protocol version, the cipher, the subject and the issuer. If the subject does not match the host name Cloudflare sends, or the chain is incomplete, fix the certificate or lower the mode only as a deliberate, temporary diagnostic. The TLS reference explains the chain and SNI behaviour, and the Cloudflare hub lists the related codes.

Firewall and the IP allowlist

Cloudflare publishes the IP ranges it connects from, and those ranges change. The official list lives at cloudflare.com/ips and in the Cloudflare IP addresses documentation; use the published list rather than a copied one, and keep whatever consumes it — a host firewall, a WAF at the origin, a load balancer ACL, a .htaccess rule — refreshed when Cloudflare announces changes. This guide does not reproduce the list, because a stale copy is worse than no copy.

Two failure shapes point here. A 522 with no request in the origin log means packets were dropped before the application: a rate limit, an iptables rule, a cloud security group, or a host firewall that allows your office and blocks everyone else. A 520 with intermittent success means some edge nodes are being rejected while others are not. Neither is fixed by editing application code.

Test from outside your own network, not only from the machine that already has an exception. If the origin only answers your IP, it will answer you and fail for Cloudflare.

HTTP/2, oversized headers and idle origins

Cloudflare connects to origins over HTTP/2 when the origin advertises it through ALPN. If the server accepts the connection but does not actually speak HTTP/2, the reply is unparseable and the visitor sees 520. The origin logs may show a completed request with a 200, because from the server's side nothing failed. Disabling HTTP/2 to Origin — Speed > Settings > Protocol Optimization — is the documented way to confirm this, and the correct long-term fix is repairing the server's HTTP/2 support.

Response headers over 128 KB also produce 520, most often because a site accumulates cookies. Check the Set-Cookie count on the origin response; a handful of large cookies across several domains is enough. Idle origins produce 522: keepalives disabled, a worker pool exhausted, or a process that accepts the socket and never writes a byte. When the origin accepts TCP but sends nothing within the documented window, the edge gives up and writes the error page itself.

Decision path

  1. Does the error follow one path, or every path? One path: application or rule. Every path including static assets: origin, DNS, TLS or firewall.
  2. Does the origin answer 200 when called directly? Yes: the edge-to-origin hop is the fault. No: the origin application or its dependencies are.
  3. Is the origin's IP in the request log? No request at all: firewall, allowlist or DNS. A request with a crash or timeout: application.
  4. Does the code change with a DNS-only record or paused Cloudflare? If it disappears, the fault is in the proxy path; if it persists, the origin was always the problem.
  5. Is the reply malformed rather than absent? Oversized headers, a crashed PHP worker or an HTTP/2 mismatch all produce 520 with a 200 in the origin log.
  6. Still unresolved? Collect the evidence below rather than changing several settings at once.

Evidence to collect

Record the exact URL, the status code, the timestamp with time zone, and the cf-ray value from the error page; the Ray ID ends with the code of the data centre that served the request, which is useful when only some locations fail. Add the origin's access and error log lines for the same timestamp, the output of the origin-direct curl, the certificate subject and issuer, and whether the failure reproduces with Cloudflare paused. That set answers the only two questions support will ask: did the request reach the origin, and what did the origin send back. The HTTP reference covers the status-code semantics behind the rest.

Sources

Search the code you are seeing

Every page links the official source and the date it was last checked.

Search codes