Your site throws a Cloudflare 520, 521, or 524 error page. Users are complaining. You open Cloudflare's status page and it says everything is operational. So is the problem on Cloudflare's edge network, or on your origin server? The error page alone does not make this obvious, and guessing wrong means you either waste time debugging your server when Cloudflare's edge is the issue, or you open a support ticket with Cloudflare when your own web server is actually down. Two pieces of information settle this quickly: the cf-ray response header and the specific 52x error code.
What cf-ray actually tells you
Every HTTP response that passes through Cloudflare includes a cf-ray header. It looks something like 8f3a2b1c0d4e5f6a-SIN. The first part is a hex request ID unique to that request. The three-letter suffix is the IATA airport code of the Cloudflare data center (edge node) that handled the request. SIN means Singapore, LAX means Los Angeles, CGK means Jakarta, and so on.
This header matters during an incident for two reasons:
- The data center code tells you which edge location processed your request. If Cloudflare has a localized outage affecting one data center, you can confirm whether your traffic is hitting that specific location.
- The ray ID is what Cloudflare support needs to trace a specific failed request through their internal logs. Without it, they cannot investigate.
Grab it with curl:
curl -sI https://your-domain.com | grep -i 'cf-ray\\|HTTP/'
Sample output format:
HTTP/2 520
cf-ray: 8f3a2b1c0d4e5f6a-SIN
That output tells you two things: the request reached Cloudflare's edge in Singapore, and the edge returned a 520. Now you need to figure out whether the 520 means your origin failed or Cloudflare's edge failed.
What each 52x code points to
All 52x errors share one trait: the connection between the visitor and Cloudflare's edge succeeded, but something broke between Cloudflare's edge and your origin server. These are not standard HTTP status codes. Cloudflare invented them to describe specific failure modes on that edge-to-origin leg.
| Code | Name | What typically broke |
|---|---|---|
| 520 | Web Server Returns an Unknown Error | Origin sent an empty, malformed, or oversized response that Cloudflare could not parse |
| 521 | Web Server Is Down | Origin refused the TCP connection entirely (web server process stopped, or firewall blocking Cloudflare IPs) |
| 522 | Connection Timed Out | TCP handshake between Cloudflare edge and origin never completed (network issue or origin overloaded) |
| 523 | Origin Is Unreachable | DNS for the origin resolved but no route to host (origin IP unreachable) |
| 524 | A Timeout Occurred | TCP connected fine, but origin did not send an HTTP response within the timeout window |
| 525 | SSL Handshake Failed | TLS handshake between Cloudflare edge and origin failed (expired cert, mismatched SNI, wrong SSL mode) |
| 526 | Invalid SSL Certificate | Origin presented a certificate Cloudflare could not validate (self-signed cert with Full Strict mode) |
Key pattern: every 52x error means Cloudflare's edge is working (it received your request and tried to reach origin). The failure is almost always on the origin side or the network path to it. The exception is during a genuine Cloudflare infrastructure incident where their edge nodes cannot route to origins even though origins are healthy, but that is rare and typically shows up on cloudflarestatus.com.
For a related walkthrough on reading cf-ray and cf-cache-status headers when you get a 503 but your origin seems healthy, see Cloudflare 503 but Origin Is Healthy? Read cf-ray and cf-cache-status Headers to Find the Fault.
Verify from your origin's access logs
The fastest way to confirm whether the request even reached your origin: check your web server's access log for the same time window.
If you run Apache on a typical Debian/Ubuntu setup, the default access log path is often /var/log/apache2/access.log. On CentOS/RHEL it is typically /var/log/httpd/access_log. Nginx usually logs to /var/log/nginx/access.log. These paths vary depending on your configuration, so check your virtual host or server block config if the defaults do not exist.
Search for requests around the time of the error:
# Check last 50 lines of access log for recent requests
tail -50 /var/log/nginx/access.log
What you are looking for:
- No matching request in the log at all: Origin never received the request. Points to 521 (connection refused), 522 (TCP timeout), or 523 (unreachable). Your web server process might be down, or a firewall is dropping connections from Cloudflare's IP ranges.
- Request present but with a 5xx status: Origin received the request and returned an error. Points to 520 (if the response was malformed or empty) or 524 (if the origin took too long and Cloudflare gave up waiting).
- Request present with a 200 status: Origin thinks it responded fine. This can still cause a 520 if the response headers were malformed, oversized, or if the connection was reset mid-transfer.
Check if your firewall blocks Cloudflare
A 521 (Web Server Is Down) is one of the most common 52x errors, and a frequent cause is a firewall on the origin that blocks Cloudflare's edge IP ranges. When Cloudflare proxies a request, the connection to your origin comes from a Cloudflare IP, not the visitor's IP. If your firewall only allows specific IPs or has rate-limiting that catches Cloudflare's request volume, connections get refused.
Check whether your server can accept connections from Cloudflare IPs. On a server with iptables:
# List current firewall rules (read-only, safe to run)
iptables -L -n | head -40
Look for DROP or REJECT rules that might catch Cloudflare's IP ranges. Cloudflare publishes their current IP ranges at https://www.cloudflare.com/ips/. If you maintain an allowlist, pull the latest ranges from that page rather than hardcoding them, because Cloudflare adds new ranges periodically.
Also verify your web server process is actually running and listening on the expected port:
ss -tlnp | grep -E ':80|:443'
If nothing is listening on port 443 (or 80, depending on your Cloudflare SSL mode), that explains a 521 immediately.
Distinguish edge failure from origin failure during a real outage
During a widespread incident, the question is whether Cloudflare's edge infrastructure itself is broken or whether your origin is the problem. Here is a quick decision process:
- Grab the cf-ray header from the error response. If you get a cf-ray header at all, Cloudflare's edge is responding. The edge is alive.
- Note the data center code in cf-ray. Check Cloudflare's status page for incidents affecting that specific data center.
- Check the specific 52x code. A 521 or 522 strongly suggests your origin is unreachable. A 525 or 526 points to an SSL/TLS configuration mismatch between Cloudflare and your origin.
- Check your origin access logs. If the request never arrived at your origin, the break is in the network path between Cloudflare's edge and your server. If the request arrived and your origin returned an error or timed out, the problem is on your side.
- Test origin directly. If your origin has a public IP you can reach without going through Cloudflare, curl it directly to see if it responds. This bypasses Cloudflare entirely and tells you whether the origin is fundamentally healthy.
If cf-ray is missing entirely from the response, the request may not have reached Cloudflare at all, which points to a DNS issue or a problem upstream of Cloudflare's network.
When to escalate to Cloudflare vs. fix it yourself
Most 52x errors are origin-side problems. The origin server is down (521), overloaded and timing out (522, 524), or has an SSL certificate issue (525, 526). These you fix yourself: restart the web server, check the firewall, renew the certificate, or increase timeout values.
Escalate to Cloudflare when:
- Your origin responds correctly to direct requests (bypassing Cloudflare), but requests through Cloudflare still fail.
- The cf-ray data center code matches a location listed on Cloudflare's status page as having issues.
- You see 52x errors from multiple unrelated origins behind Cloudflare simultaneously, suggesting an edge-side problem rather than a single origin failure.
When you do escalate, include the cf-ray ID from the failed request. Without it, Cloudflare support cannot trace what happened on their side. Include several ray IDs if you have them, from different time windows, so they can see a pattern.
The whole point of this process is avoiding the two worst outcomes during an incident: spending an hour debugging your server when Cloudflare's edge is broken, or waiting on a Cloudflare support ticket when your own Nginx has been down the entire time. Grab the cf-ray, check the error code, check your logs. Three steps, usually under five minutes, and you know which side to fix.