Skip to content
5xx · server errorSent by CDNNon-standard · Cloudflare

520Web Server Returned an Unknown Error

Cloudflare reached your server and got back something empty or unreadable.

How you get a 520

Cloudflare passes the request to your origin. The app crashes while answering and the connection ends with an empty reply. Cloudflare cannot make a response out of nothing, so the CDN sends 520.

Who sends itCDN

  1. Browser
  2. CDN
  3. Proxy
  4. App
  5. DB

Only Cloudflare sends it. It is Cloudflare's own code for a reply from your origin server that it could not interpret. Other CDNs and proxies would typically answer 502 in the same situation.

In short

What a 520 Web Server Returned an Unknown Error means

A 520 is not part of the HTTP standard. Cloudflare invented it for the case where it connected to your origin server, sent the request, and got back something it could not interpret: an empty reply, a connection reset partway through, or a response that breaks HTTP's rules. Cloudflare writes the error page and the status by itself. Seen from your side it is close to what other proxies call 502 Bad Gateway. The cause is almost always behind Cloudflare: an application that crashes while answering, a web server that drops connections under load, or response headers too large for Cloudflare to accept. The quickest test is to send the same request straight to the origin, bypassing Cloudflare, and look at what comes back.

Common causes of a 520

  1. 1The origin application crashed or was restarted while answering.

    How to check: Send the same request directly to the origin and see whether the connection drops.

    curl -sv --resolve example.com:443:<origin-ip> https://example.com/path
  2. 2The origin resets or closes connections, for example under load or because of a firewall.

    How to check: Look at the origin's web server and firewall logs for the time shown on the error page.

  3. 3The origin's response headers are too large, often because of many or very big cookies.

    How to check: Measure the header size of the direct response.

    curl -sI --resolve example.com:443:<origin-ip> https://example.com/path | wc -c
  4. 4The origin sent an empty or malformed HTTP response.

    How to check: The direct request returns “Empty reply from server”, or headers that are incomplete.

Retry or not?

Safe to retry with backoff · Idempotent requests

Like a 502, it often clears quickly if the origin was restarting. The origin may have done part of the work before it failed, so only repeat requests that are safe to repeat.

Headers that matter

cf-ray
Cloudflare's ID for this request. Use it to find the request in Cloudflare's logs and to match the time in your origin's logs.
Server: cloudflare
Confirms the page was written by Cloudflare and not by your origin.

In the real world

RFC vs real deployments

No RFC mentions 520; codes 520 to 527 are Cloudflare's private range for problems between its edge and your origin. Standard software in the same position would answer 502. Because the number is vendor-specific, generic HTTP clients simply treat it as an unknown 5xx server error, which is what the standard tells them to do with codes they do not recognise.

Seen in a real outage

When the edge itself misbehaves, every site behind it shows errors at once. In June 2021 Fastly returned errors from 85% of its network, seconds after one customer saved a valid setting that triggered a hidden bug.

Your turn

Which code is it?

Visitors see a Cloudflare page with error 520. Calling the origin directly with curl prints “Empty reply from server”. Where is the problem?

520 questions

Is 520 a standard HTTP status code?
No. It is specific to Cloudflare. It means Cloudflare got an empty, unknown or unexpected reply from the origin server.
Who sends a 520?
Cloudflare's edge. Your origin server did not send it; Cloudflare generated it because it could not interpret what the origin returned.
What is the difference between 520 and 502?
They describe similar failures. A 502 is the standard code a proxy uses for an invalid reply from the server behind it. A 520 is Cloudflare's own code for much the same thing.

Sources: Cloudflare: Error 520 ↗ · Report a problem

Diagrams are our own simulations. All wording is original and paraphrases the linked sources.

Practise this in the DNS / HTTP track

Two-minute animated lessons, then boss fights from real outages. Free, no account needed.

Start the track