failover.io
  1. Home
  2. Cloudflare errors
  3. Error 520

Cloudflare error 520: Web server returned an unknown error

HTTP 520 from Cloudflare. Unknown error from the origin: what it means, whose fault it is and how to fix it.

Updated 19 November 20265 min read

Cloudflare returns a 520 when it reached your origin server but got an answer it couldn't use: empty, malformed or cut off halfway. Your server isn't down; it answered badly, so the cause is almost always in your application or web server.

Quick answer. Check your application's error log at the time of the 520. The usual causes are an app that crashed mid-response, response headers over Cloudflare's 16 KB limit (often from large cookies), an empty reply or a firewall or security plugin on the origin that interferes with Cloudflare's requests.

Is a 520 error my fault?

Where the problem isHow often
Your originAlmost always
CloudflareRarely
The visitorNo

Cloudflare shows the error page, but the trigger is on your side: it reached your server and got a reply it couldn't read. That rules out DNS failures, a server that's fully down and routing problems, which produce other codes, and points at the application.

What error 520 means

A request to a Cloudflare-proxied site goes to Cloudflare first, which forwards it to your origin and passes the answer back. A 520 means that relay broke: Cloudflare connected and sent the request, but what came back wasn't a valid HTTP response. It might be an empty body, headers that break the rules or a connection that closed in the middle of the reply.

That makes 520 the hardest code in the family to debug. The others point somewhere: 521 is a refused connection, 522 a connection that timed out and 525 a failed TLS handshake. A 520 only says the answer made no sense.

Common causes, most likely first

  1. The application crashed while answering. The server starts the response, then an unhandled exception, an out-of-memory kill or a script that dies halfway stops it, and Cloudflare gets a partial or empty reply. Check the application log (PHP-FPM, your Node process, your Python worker) at the time of the error.
  2. The response headers are over 16 KB. Cloudflare drops a response whose headers pass that limit, and large cookies are the usual reason, followed by long lists of security headers and big session tokens.
  3. A firewall, security plugin or .htaccess rule on the origin blocks or mangles Cloudflare's requests. Rename .htaccess for a moment and test again; if the 520 goes away, add the rules back one block at a time to find the bad one.
  4. The server sends a status and headers, then closes the connection before the body. This often comes from a reverse proxy in front of the app (nginx, HAProxy) that times out or routes the request to the wrong place.
  5. The origin's HTTP/2 setup is wrong. Cloudflare lists this as a cause; turning HTTP/2 to the origin off for a test tells you quickly if it's yours.

How to find the cause in your server logs

Reproduce the bad response without Cloudflare in the way. That tells you whether the problem is your server or the link between Cloudflare and it.

  1. Take your origin IP from the Cloudflare DNS settings and call it directly: curl -v --connect-timeout 10 --resolve yourdomain.com:443:ORIGIN_IP https://yourdomain.com/. The same broken response means the problem is your server and Cloudflare is only reporting it.
  2. Follow the application and web server error logs while you send the request. A crash, an out-of-memory kill or a segfault shows up with a matching timestamp.
  3. Look at the response headers with curl -sI and make sure they're nowhere near 16 KB.
  4. If the origin answers cleanly when you call it directly but Cloudflare still shows 520, the problem is in the relay: a crash that only happens under Cloudflare's request pattern, or under load. Check whether the errors line up with busy periods.

Does a 520 error hurt SEO?

A short one doesn't. Google's crawlers slow down when a site returns 5xx errors, and Google says URLs that keep returning a server error are eventually dropped from its index. A 520 that lasts a few minutes costs nothing; one that keeps coming back for days can cost you pages in search.

Get alerted when your site returns 520

A 520 often comes and goes with load, so you only see it if something checks all the time. An HTTP monitor that expects a 200 fails on a 520, and adding text that must not appear also catches error pages served with a 200.

All six codes side by side: Cloudflare 5xx errors explained.

Frequently asked questions

What does Cloudflare error 520 mean?

Cloudflare connected to your origin server, but the answer was empty, malformed or cut off, so Cloudflare couldn't use it. Your server is reachable; it answered badly.

Is error 520 Cloudflare's fault or my server's?

Almost always your server's. Cloudflare shows the error, but the cause is usually a crashed application, response headers over 16 KB or a security rule on the origin.

How do I fix Cloudflare error 520?

Check the application error log at the time of the error, make sure response headers stay under 16 KB with curl -I, rename .htaccess for a test and call your origin IP directly to see the response without Cloudflare.

What is the difference between error 520 and 521?

With a 520 the connection worked but the answer was unreadable. With a 521 the origin refused the connection, usually because the web server is stopped or a firewall blocks Cloudflare.