BuyProxy logo
Log inSign up

Cloudflare 520Cloudflare errors

Cloudflare error code 520: what it means and how to fix it

Short answer

Cloudflare error 520 means Cloudflare connected to the website's own server (the origin) and got back something it couldn't use: an empty response, a closed connection or a response that isn't valid HTTP. It is Cloudflare's catch-all for an unexpected answer from the origin. The problem is between Cloudflare and the site's server, so visitors can't fix it; the site owner can.

A Cloudflare error number, not a standard HTTP status code.

What causes error 520

  • The origin crashed or restarted while handling the request.
  • The origin closed the connection without sending a response, for example when a process was killed or hit a limit.
  • An empty or malformed response: no status line, broken headers, or headers larger than Cloudflare accepts (many or large cookies are a common culprit).
  • A firewall or security tool on the origin that resets connections from Cloudflare's IP addresses.

Who sends error 520?

Cloudflare sends the 520 page, but the cause is the site's origin server. Your proxy and your browser aren't involved: the request reached Cloudflare, and Cloudflare's own request to the origin is what failed. The page shows the error and a Ray ID, and the response carries Server: cloudflare and a CF-Ray header. Unlike most Cloudflare error numbers, 520 is also the HTTP status code of the response.

It belongs to a family of Cloudflare 5xx codes about the connection to the origin: 521 means the origin refused the connection, 522 that the connection timed out, 523 that the origin is unreachable, 524 that the origin connected but didn't answer in time, and 525 and 526 that the TLS handshake or the certificate check failed.

How to fix error 520

If you are the visitor

  1. Reload once after a short wait. A 520 caused by a restart can clear in seconds.
  2. If it persists, the site is having trouble. Try later, or give the site owner the Ray ID and the time.
  3. There is nothing to change on your side: not your browser, your network or your proxy.

If you run the site

  1. Check the origin's error logs at the time of the Ray ID for crashes, killed processes or resets.
  2. Send a request straight to the origin server, without Cloudflare in the path, and inspect the raw response for a missing status line or broken headers (example below).
  3. Make sure the origin's firewall and security plugins allow Cloudflare's IP ranges.
  4. Look for unusually large response headers, such as many or large cookies.
  5. If you can't find the cause, open a ticket with Cloudflare support and include the Ray ID.

Test the origin and retry once: curl and Python

bash
# Site owners: ask the origin (203.0.113.10 here) for your site directly, without Cloudflare.
# -i prints the status line and headers: a 520 often means they are missing or broken.
curl -sS -i --resolve www.example.com:443:203.0.113.10 https://www.example.com/

# The same page through Cloudflare, for comparison
curl -sS -o /dev/null -D - https://www.example.com/ | grep -iE "^(HTTP|server|cf-ray)"
python
import time

import requests

CLOUDFLARE_ORIGIN_ERRORS = {520, 521, 522, 523, 524}


def get_once_more(url, proxies=None):
    r = requests.get(url, proxies=proxies, timeout=30)
    if r.status_code in CLOUDFLARE_ORIGIN_ERRORS and r.headers.get("Server", "").lower() == "cloudflare":
        time.sleep(10)  # one retry after a pause; repeated 520s mean the site is down
        r = requests.get(url, proxies=proxies, timeout=30)
    return r

Error 520 and proxies

A 520 means your request got through to Cloudflare. Changing proxy, IP or country won't change how the site's origin answers Cloudflare, so retrying through other exits only adds load to a site that is already failing.

In a data job, treat repeated 520s like an outage: pause that site, retry later with backoff, and carry on with other work.

Cloudflare error 520: frequently asked questions

What does error code 520 mean?

Cloudflare reached the website's own server and got an empty, unknown or invalid response. It is a problem between Cloudflare and that server.

Is error 520 my fault?

No. It comes from the site's server. Wait and reload, or give the site owner the Ray ID and the time.

How do I fix error 520 on my website?

Check your origin's logs at the time of the error, request a page straight from the origin to see the raw response, make sure your firewall allows Cloudflare's IP ranges, and look for oversized headers or crashing processes.

What is the difference between error 520 and 521?

520 means the origin answered with something Cloudflare couldn't use. 521 means the origin refused the connection entirely, usually because the web server is down or a firewall blocks Cloudflare.

Testing proxies for a project? There is no free trial period, but support can add 100 MB of free Premium Residential bandwidth to a new account on request, by chat, Discord or email, so you can try your own targets first.

Residential proxies