Find the response Cloudflare couldn't make sense of

Cloudflare error 520 means your origin server answered Cloudflare with something empty, unknown or unexpected, so Cloudflare had no valid response to pass on to the visitor. The reply it couldn't use came from your side: a process that crashed mid-request, a firewall cutting off Cloudflare's traffic, response headers that grew too large, an HTTP/2 setup that doesn't hold up, or an origin that isn't set up for the client certificate Cloudflare presents.

What makes a response unknown to Cloudflare

  • The origin crashed mid-request

    The web server or the app behind it died while handling the request, and the connection closed with no usable reply. Cloudflare notes that 520s are common with some PHP applications that crash the web server.

  • A firewall blocks Cloudflare's addresses

    A firewall or security plugin on your server treats some of Cloudflare's IP addresses as hostile, and those requests come back with nothing Cloudflare can use.

  • Headers over 128 KB

    Response headers that add up to more than 128 KB trigger a 520. Too many cookies, or cookies holding too much data, are the usual reason.

  • HTTP/2 that breaks after it starts

    Your server tells Cloudflare it speaks HTTP/2, accepts the connection, then doesn't follow the protocol, so the reply can't be read.

  • A reply with no status or headers

    Every response needs a status code and valid headers. A handler that writes nothing, or writes malformed headers, leaves Cloudflare with an empty or broken reply.

  • A client certificate the origin won't accept

    With Authenticated Origin Pulls turned on, Cloudflare presents a client certificate to your server. If the server isn't set up to accept it the way Cloudflare expects, the request fails with a 520.

Cloudflare's error 520 guide lists these causes, including the 128 KB header limit and the HTTP/2 case, and notes that 520s are common with certain PHP applications that crash the origin web server. Its Authenticated Origin Pulls page explains the client certificate.

Request your origin directly and measure the headers

# Send the request straight to your origin's IP address (203.0.113.10 here), skipping Cloudflare.
# Add -k if curl rejects the origin's certificate; this test looks at the response, not the certificate.
curl -sS -o /dev/null --connect-to ::203.0.113.10 https://yoursite.com/ \
  -w "status %{http_code}, headers %{size_header} bytes\n"

# Try HTTP/2 and HTTP/1.1 separately to see whether only one of them fails
curl -sS -o /dev/null --http2 --connect-to ::203.0.113.10 https://yoursite.com/ -w "HTTP/%{http_version} %{http_code}\n"
curl -sS -o /dev/null --http1.1 --connect-to ::203.0.113.10 https://yoursite.com/ -w "HTTP/%{http_version} %{http_code}\n"

What the direct request tells you

  • If the direct request fails too, the problem is on your server, and its error log at that minute should show the crash. When the connection closes without a single byte of response, curl exits with code 52, which curl's error list describes as nothing returned from the server.

  • If the direct request works, compare it with what Cloudflare gets. A header total close to 128 KB, or a failure over HTTP/2 that HTTP/1.1 doesn't have, matches two of the causes in Cloudflare's guide. If nothing differs, check the firewall and any load balancer, cache or proxy between Cloudflare and the server: Cloudflare's 5xx overview points out the cause isn't always in the origin's own error log.

How to fix Cloudflare error 520

  1. Find the crash in the server's logsOpen the web server and application error logs at the minute of the 520. A worker that segfaulted, ran out of memory or hit a fatal error explains an empty response.
  2. Unblock the addresses Cloudflare usesSearch the firewall and any security plugin for denies or rate limits that match Cloudflare's published ranges, and remove them so every range gets through.
  3. Shrink oversized headersFind what sets so many cookies or such long header values, such as session data or tracking state kept in the cookie itself, and store that data on the server instead.
  4. Fix or switch off HTTP/2 at the originIf HTTP/1.1 works and HTTP/2 fails in the direct test, repair the server's HTTP/2 setup, or stop advertising HTTP/2 until it works.
  5. Answer failures with a proper statusMake sure the app and web server reply to errors with a valid status such as 500 or 503 instead of closing the connection, so the next failure reaches you with a readable error.

Frequently asked questions

Is error 520 Cloudflare's fault?

Rarely. Cloudflare draws the 520 page, but it does so because your origin's reply was empty or unreadable. Cloudflare's 5xx overview suggests giving your host the error code, the time with its time zone and the URL that failed, so they can find the matching entry in the server's logs.

Why do I get a 520 only on some pages?

Look at what those pages do differently. A page that sets many cookies can push its headers past the limit, and a page that runs a heavy script is the one most likely to crash its worker. Cloudflare's guide adds that when your origin returned a 200 and visitors got a 520, the response was probably malformed, for example oversized headers or a connection closed early.