Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Cloudflare Error 520: Web server is returning an unknown error

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

Cloudflare Error 520 means Cloudflare contacted your origin, but the answer was empty, unknown or unexpected. Visitors see Cloudflare's error page. Repair what the origin sends. DNS-only or a pause only proves whether the origin can answer without the proxy.

What the symptom means

Cloudflare titles the fault "Error 520: web server returns an unknown error" and states that "This error occurs when the origin server returns an empty, unknown, or unexpected response to Cloudflare." That is not Error 521 (connection refused) or Error 522 (connect timeout). Contact often starts; the HTTP answer does not.

Triggers include origin crashes or misconfigurations, firewalls or security plugins blocking Cloudflare IPs, "Headers exceeding 128 KB (often due to excessive cookies)", empty or malformed responses, missing response headers, incorrect HTTP/2 at the origin, and Authenticated Origin Pull enabled while the origin is not configured as expected. The same page notes: "520 errors are prevalent with certain PHP applications that crash the origin web server."

Likely causes

Cause What you see How to confirm
Origin crash or misconfiguration 520 with matching origin log fatals Match cf-ray time to the origin error log
Firewall or plugin blocks Cloudflare IPs 520 after a WAF or plugin change Confirm Cloudflare ranges are allowed
Response headers over 128 KB 520 on cookie-heavy paths Measure response header size at the origin
Empty or malformed HTTP response 520 while the process still runs Capture a direct origin response
Broken HTTP/2 on the origin 520 after HTTP/2 to Origin is on Disable HTTP/2 to Origin and retest
Authenticated Origin Pull mismatch 520 after Origin Pull was enabled Confirm the origin expects the client certificate

Prove the cause before changing anything

These steps only read.

  1. Copy the full URL, time and cf-ray. Cloudflare also asks for output from:
http://<YOUR_DOMAIN>/cdn-cgi/trace

and, for support cases, two HAR files (Cloudflare enabled, then temporarily disabled).

  1. Read the origin error log for that timestamp for PHP fatals, worker crashes or abrupt closes.

  2. In Origin Analytics, compare originResponseStatus with edgeResponseStatus. If the origin returned a 200 but Cloudflare served a 520, "the response was likely malformed — for example, oversized headers or an early connection close."

  3. Do not treat OriginResponseStatus = 0 alone as a 5xx from the origin: "Do not conclude your origin returned a 5xx error solely because OriginResponseStatus = 0. Always check CacheStatus first to determine whether Cloudflare contacted the origin at all."

Fix

Repair the origin response. Do not leave the hostname on DNS-only as the lasting fix.

"As a temporary workaround, you can set the affected DNS record to DNS-only in the Cloudflare DNS app or temporarily pause Cloudflare."

Save the current proxy state first (Proxied or DNS only):

echo "www.example.com proxied=yes" > cloudflare-dns-proxy-before.txt

Risk: the next step sets the hostname to DNS-only (grey cloud), so visitor traffic goes straight to the origin IP and no longer passes through Cloudflare's proxy for that name until you reverse it.

In the Cloudflare DNS app, set the failing A or CNAME to DNS only. Retest the URL. If the origin answers cleanly, the fault is in what Cloudflare receives while proxied.

To undo it: set the same DNS record back to Proxied per cloudflare-dns-proxy-before.txt.

With the origin reachable for diagnosis, fix the cause you proved:

  • If a firewall or security plugin blocks Cloudflare, the Error 520 page names that as a cause. The allow-list steps with save-first, risk and back-out are in Error 521; proxied visitors appear to come from Cloudflare, so blocking those ranges prevents visitor traffic from reaching the application.
  • If headers exceed 128 KB, the page names "Headers exceeding 128 KB (often due to excessive cookies)" as a cause. Reducing cookies or other oversized headers at the application is this article's own step so the response fits under that limit.
  • If HTTP/2 at the origin is wrong, Cloudflare connects when the origin announces HTTP/2 via ALPN and returns 520 when the origin accepts HTTP/2 then does not respect the protocol. Cloudflare says you can disable HTTP/2 to Origin under Speed > Settings > Protocol Optimization, or repair HTTP/2 on the origin.
  • If Authenticated Origin Pull is enabled on Cloudflare but the origin is not configured as expected, the Error 520 page lists that only as a cause. Configure the origin for Origin Pull, or leave the setting alone until that configuration is ready; the page does not tell you to turn Origin Pull off.

Save the Protocol Optimization setting before you change it. Write the value the dashboard shows for HTTP/2 to Origin (the page gives no default):

echo "http2_to_origin=<value shown in Protocol Optimization>" > cloudflare-http2-to-origin-before.txt

Risk: the next step turns off HTTP/2 to Origin for the zone, which can change connection reuse and performance until you turn it back on.

In Speed > Settings > Protocol Optimization, disable HTTP/2 to Origin. Retest the URL that returned 520.

To undo it: restore HTTP/2 to Origin to the value in cloudflare-http2-to-origin-before.txt.

Example (illustrative): checkout returns 520 with origin 200 and edge 520 while Set-Cookie headers are oversized. After reducing session cookies so response headers sit under 128 KB (this article's own remediation of the page's cause), the 520 stops with DNS still proxied.

Confirm the fix

  1. With the hostname proxied again, reload the failing URL; it should not return Error 520.
  2. Confirm analytics no longer pairs that path with 520.
  3. If you used DNS-only, confirm the record is Proxied again.

What to watch afterwards

  • Security plugin updates that re-block Cloudflare IP ranges.
  • Login and cart paths where cookies grow past 128 KB.
  • Authenticated Origin Pull enabled before the origin is ready.
  • Connect failures that never produce HTTP: nginx 502 connection refused and Error 521.

Risks and limits

These steps have not been lab-tested.

DNS-only removes proxy protections while grey-clouded. OriginResponseStatus of 0 with CacheStatus hit or revalidated is not an origin 5xx. Disabling HTTP/2 to Origin does not repair empty HTTP/1.1 bodies. Error 520 has no separate connect timeout figure; 522 and 524 cover those timers.

Sources

  • Error 520 — Cloudflare, Last updated Jun 16, 2026, accessed 1 December 2026
  • Cloudflare IP addresses — Cloudflare, Last updated Apr 21, 2026, accessed 1 December 2026