520 Web Server Returned an Unknown Error
Cloudflare reached your origin server and got a reply it could not make sense of: nothing at all, a connection that ended early, or a response that broke its rules.
What 520 means
520 is Cloudflare's catch-all for an origin that answered wrongly, as opposed to one that could not be reached. Cloudflare connected, sent the request, and what came back was empty, unknown or unexpected. The other 52x codes each name a specific failure; 520 is what remains.
It is Cloudflare's own code, not part of HTTP, and only Cloudflare's edge generates it. Visitors cannot fix it. If the site is yours, the answer is on the origin server.
Causes Cloudflare documents
- The origin application crashed while handling the request, so the connection closed with no response. Cloudflare singles out PHP applications that take the web server down with them.
- Response headers that are too large. Cloudflare gives a limit of 128 KB for headers, and the usual way past it is a pile of cookies.
- An empty or malformed response: no status line, missing headers, or an origin that does not return proper HTTP error responses.
- A firewall or security plugin on the origin that interferes with connections from Cloudflare's addresses.
- Broken HTTP/2 at the origin. The server advertises HTTP/2 during the TLS handshake and then does not speak it correctly.
- Authenticated Origin Pulls switched on in Cloudflare while the origin is not set up to accept the client certificate.
Tracking it down
- Bypass Cloudflare for one request.
curl -sv --resolve example.com:443:203.0.113.10 https://example.com/path, with your origin's address, sends the request straight to the origin under the right host name. An empty reply or a reset connection there confirms the origin is at fault. - Read the origin's logs for the same second. Look for a crashed worker, a segfault, an out-of-memory kill, or an nginx
upstream prematurely closed connectionentry. If the access log shows a normal 200 for the request, suspect the headers. - Measure the headers. Count the
Set-Cookielines and their sizes in the direct response. - Rule out HTTP/2. Turn off "HTTP/2 to Origin" (Speed > Settings > Protocol Optimization in the dashboard) and see whether the errors stop.
- Check whether it is one URL or all of them. One URL points at application code; all of them at the server, a firewall or a certificate setting.
Setting the DNS record to DNS-only, or pausing Cloudflare, is a temporary workaround that also shows visitors the origin's raw behaviour. If you need Cloudflare's support, they ask for the full URL, the cf-ray value from the error, the output of /cdn-cgi/trace on your domain and HAR files recorded with Cloudflare on and off.
520 next to the other Cloudflare 52x codes
| Code | How far Cloudflare got |
|---|---|
| 521 | The origin refused the TCP connection |
| 522 | The TCP connection to the origin timed out |
| 523 | No network route to the origin |
| 520 | Connected and sent the request; the reply was empty or invalid |
| 524 | Connected and sent the request; no reply arrived in time |
Without Cloudflare in front, a proxy such as nginx would report most 520 situations as a 502 Bad Gateway.
Example 520 response
HTTP/2 520
date: Sat, 14 Nov 2026 09:41:07 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
cf-ray: 8e2a1b3c4d5e6f70-LHRThe body, left out here, is Cloudflare's HTML error page. cf-ray identifies this one request at Cloudflare's edge; the letters after the hyphen are the code of the data centre that served it.
Documented in Cloudflare docs: Error 520.
Questions
Is a 520 error caused by Cloudflare or by my server?
Cloudflare generates the error, but the cause is the origin: it returned an empty, incomplete or invalid response. Fetch the same URL directly from the origin to see the underlying failure.
How do I fix error 520?
Find out what the origin sent. Check its error logs for crashes at the time of the error, look for very large cookies or headers, make sure no firewall on the origin interferes with Cloudflare, and try turning off HTTP/2 to Origin. Fix whichever of these the evidence points to.
Why does a 520 happen only for logged-in users?
Logged-in requests carry and receive more cookies. If the response headers grow past the size Cloudflare accepts, it reports a 520 although the origin believes it sent a normal page. Reduce the number and size of the cookies your application sets.
Can a visitor fix a 520 error?
No. It is a fault between Cloudflare and the website's server. Trying again later is all a visitor can do, apart from clearing that site's cookies in the oversized-header case.