Cloudflare Error 520 "Web Server Is Returning an Unknown Error": Causes and Fixes
Cloudflare error 520 means your origin sent an empty, malformed or cut-off response. The common causes, how to bypass Cloudflare to test, and how to fix it.
Cloudflare error 520 means Cloudflare reached your server (the "origin") and got a response it could not use: empty, malformed, cut off mid-way, or with headers that are too large. Cloudflare itself is working. Something on your server answered badly, so the fix is almost always on the origin: a crashing app, oversized cookies or headers, a firewall resetting Cloudflare's connections, or an HTTP/2 setting the origin can't handle.
Checked against Cloudflare's Error 520 troubleshooting page, its connection limits and HTTP headers reference in November 2026.
The error page looks like this:
Web server is returning an unknown error
Error code 520
Cloudflare Ray ID: 8f2a1b3c4d5e6f70
Cloudflare's own docs title it "Error 520: web server returns an unknown error". The Ray ID is different on every request; write it down, you'll use it below.
Where 520 sits among Cloudflare's 52x errors
All the 52x errors mean "the problem is between Cloudflare and your server". They differ in how far the connection got:
| Code | What happened |
|---|---|
| 521 | Your server refused the connection |
| 522 | The connection timed out, nothing answered |
| 525 | The HTTPS handshake with your server failed |
| 520 | The connection worked, but the response was unusable |
If you're seeing 521, 522 or 525 instead, read Cloudflare Error 521, 522 and 525. Those are about reaching the server at all. A 520 means Cloudflare got through and your server said something it couldn't turn into a valid HTTP response.
The causes Cloudflare lists
Cloudflare's Error 520 page names these:
- The origin crashed or is misconfigured. The page notes 520s are "prevalent with certain PHP applications that crash the origin web server". If PHP-FPM, Node or your app server dies while handling a request, the connection closes without a proper response.
- A firewall or security plugin is blocking Cloudflare's IPs. Instead of dropping the traffic (which would give you a 522), it accepts the connection and then resets it.
- Headers over 128 KB. Cloudflare's connection limits set a total of 128 KB for request headers and 128 KB for response headers. Too many or too large cookies are the usual reason.
- An empty or malformed response. The origin closes the connection without sending a status line, or sends something that isn't valid HTTP.
- Missing response headers, or an origin that doesn't return proper HTTP error responses.
- Incorrect HTTP/2 configuration at the origin. If HTTP/2 to Origin is on and your server claims HTTP/2 support but handles it badly, you get a 520.
- Authenticated Origin Pulls is on in Cloudflare but the origin isn't set up to match.
Step 1: see whether it's every request or some
Open a few pages, an image and an API endpoint:
- Every request fails: the origin is down in a way that still accepts connections, a firewall is resetting Cloudflare, or HTTP/2 to Origin or Authenticated Origin Pulls is misconfigured.
- Only some pages fail: an app crash on a specific route, or a response that is too large or malformed on that route.
- Only some users fail: usually cookies. A user with a pile of tracking or session cookies can push request headers past the limit while a fresh browser works fine. Try a private window.
Step 2: bypass Cloudflare and talk to the origin directly
The fastest way to see what your server is really sending is to skip Cloudflare. With curl you can send a request to your server's IP while keeping the correct hostname (so virtual hosts and certificates still match):
curl -v --resolve example.com:443:203.0.113.10 https://example.com/failing/path
Replace example.com with your domain and 203.0.113.10 with your origin's real IP. (What is curl? covers the flags.)
What to look for:
Empty reply from serverorConnection reset by peer: the origin is closing the connection without answering. That's a crash, a worker killed mid-request, or a firewall rule.- A normal response comes back: compare the headers with what you expect. If it works here but not through Cloudflare, look at header size, HTTP/2 to Origin and firewall rules that only apply to Cloudflare's IP ranges.
- A 500 or 502: the origin is failing in a way it does report. Fix that error first. (500 Internal Server Error, 502 Bad Gateway)
To measure response header size, print only the headers and count the bytes:
curl -s -o /dev/null -D - --resolve example.com:443:203.0.113.10 https://example.com/ | wc -c
Anything approaching 128 KB is a problem. Look for repeated Set-Cookie lines or a framework that stuffs large values into headers.
Cloudflare's suggested temporary workaround is to switch the DNS record to DNS only (grey cloud) or pause Cloudflare, so visitors reach the origin directly. That tells you quickly whether the site works without the proxy. It also exposes your server's IP and turns off Cloudflare's protection while it's set, so switch back once you've seen the result. (Proxied vs DNS only explains the trade-off.)
Step 3: find the failing request in your origin logs
Every Cloudflare error page shows a Ray ID. Cloudflare also sends that value to your origin in the CF-Ray request header, and its HTTP headers reference recommends adding it to your origin's access log so you can match a Cloudflare request to a server log line.
For nginx, add it to the log format:
log_format cf '$remote_addr - [$time_local] "$request" $status '
'$body_bytes_sent ray=$http_cf_ray';
access_log /var/log/nginx/access.log cf;
Then search the access log for the Ray ID and read the error log entries around that timestamp:
grep 8f2a1b3c4d5e6f70 /var/log/nginx/access.log
sudo tail -n 100 /var/log/nginx/error.log
If the request never reached nginx at all, look earlier in the chain: the firewall, or something like fail2ban that may have banned a Cloudflare IP. If it reached nginx but the upstream app died, the app's logs (or journalctl -u yourapp) will show the crash. (What is systemd? covers journalctl.)
Cloudflare's docs also suggest comparing the origin's status with the one Cloudflare served, in Origin Analytics or Logpush. An origin 200 served as a 520 points to a malformed response, such as oversized headers or an early connection close.
Fixes by cause
The app is crashing
Fix the crash. Check memory (an out-of-memory kill looks exactly like this), PHP-FPM or Node process logs, and any request that takes the process down. Restarting buys time but the 520s will return on the same request.
A firewall or security plugin is resetting Cloudflare
When everything is proxied, all your traffic arrives from Cloudflare's IP ranges. Rate limiters, WordPress security plugins and fail2ban can decide those addresses are attackers. Allow Cloudflare's published IP ranges in your firewall and security tools, and restore the real visitor IP from the CF-Connecting-IP header so bans apply to visitors, not to Cloudflare. (fail2ban, UFW firewall basics)
Headers are too large
Trim cookies: remove ones you don't need, stop storing large data in cookies, and make sure a bug isn't setting the same cookie on every response. On the response side, check for headers that grow with the request (debug headers, long Link preload lists).
HTTP/2 to Origin
If your origin advertises HTTP/2 but doesn't handle it properly, turn off HTTP/2 to Origin in the Cloudflare dashboard under Speed > Settings > Protocol Optimization, and test again. If that fixes it, either leave it off or fix the origin's HTTP/2 configuration before re-enabling it.
Connections closed mid-reuse
Cloudflare reuses open connections to your origin, and its connection limits page notes that HTTP keep-alive "helps avoid connection resets". Keep it enabled on the origin and on any load balancer in front of it.
Authenticated Origin Pulls
If you enabled it in Cloudflare, the origin has to be configured to request and verify Cloudflare's client certificate. Either finish that setup or turn the feature off.
When to contact Cloudflare
If the origin looks healthy when you bypass Cloudflare and the 520s continue, Cloudflare support asks for: the full URLs, the Ray ID from the error, the output of https://yourdomain.com/cdn-cgi/trace, and two HAR files, one with Cloudflare enabled and one with it temporarily disabled.
Quick checklist
- Note the Ray ID and whether it's every request, some routes or some users.
curl -v --resolveto the origin IP and read what comes back.- Find the Ray ID in the origin access log; read the error log around it.
- Check for crashes and out-of-memory kills.
- Allow Cloudflare's IP ranges in firewalls and security tools.
- Check header and cookie size against the 128 KB limit.
- Try turning off HTTP/2 to Origin.
EasySpawn runs your app on a managed server with SSL and your own domain already set up, and Claude Code works on that same server, so when Cloudflare reports a 520 it can read the app's logs and find the crash without you hunting for the right machine. It won't stop an app from crashing. Join the waitlist.
Related: Cloudflare Error 521, 522 and 525: What They Mean and How to Fix Them · Cloudflare Proxied vs DNS Only: The Orange Cloud Explained · 502 Bad Gateway: What It Means and How to Fix It · What Is Cloudflare? What It Does When You Put Your Site Behind It
Keep reading
Cloudflare Error 1033 (Argo Tunnel Error): Why Your Tunnel Can't Be Reached and How to Fix It
Cloudflare error 1033 means your hostname points at a Cloudflare Tunnel that isn't connected, or at the wrong tunnel. How to check cloudflared, status and DNS.
ERR_SSL_PROTOCOL_ERROR: What It Means and How to Fix It
ERR_SSL_PROTOCOL_ERROR means the browser couldn't complete a secure HTTPS connection because the server's response wasn't valid TLS. The usual causes — HTTPS pointed at a port speaking plain HTTP, a missing certificate, localhost over https, Cloudflare SSL modes — and how to fix each.