Cloudflare Error 520 (Web Server Is Returning an Unknown Error): Causes and a Tested Fix
Error 520 (Web server is returning an unknown error) means Cloudflare connected to your web server, but the answer that came back was empty, broken or something Cloudflare could not understand. Cloudflare is working and so is the visitor’s browser. The problem is the reply from your origin server, and the typical reasons are a web server process that crashes or closes the connection mid-request, a security rule that drops the request without answering, or headers that are too large.
If you are just visiting a site that shows error code 520, there is little you can do: reload after a few minutes, or clear the cookies for that one site. If it is your site, the fix is on your server. Below I show how I caused error 520 on purpose on an Nginx server behind Cloudflare, what the server’s own logs showed when it happened, why a crashed PHP-FPM gave a different error, and the commands that find the real cause.
Tested by Dolon Bepari, 20 November 2026
- Server: a throwaway Ubuntu 22.04 VPS (1 vCPU, about 2 GB RAM), aaPanel 7, Nginx 1.30.7, PHP 8.4, WordPress
- Cloudflare: Free plan, orange cloud (proxied), SSL/TLS mode Full (strict), test domain filecafe.site
- How I measured: curl and a browser from my PC in Dhaka, Bangladesh, through Cloudflare, plus commands and logs on the server itself
- There are no affiliate links in this guide. How I test: how we review
Table of Contents
What error code 520 means
Error 520 is a Cloudflare status code, not a standard HTTP one. Cloudflare’s own error 520 page defines it as the origin server (the real server behind Cloudflare) returning an empty, unknown or unexpected response. In other words, the connection itself worked, but what came back was not a normal HTTP response that Cloudflare could pass on.
Think of 520 as a catch-all. It shows up when nothing more specific fits: the server did not refuse the connection (that would be 521), did not ignore it (522), and did not run out of time while working on the page (524). It answered with nothing, or with something broken.

Like Cloudflare’s other connection error pages, it shows three boxes. A red Host box means Cloudflare is pointing at your server, not at itself and not at the visitor.
Is error 520 your fault? Visitor vs site owner
If you are a visitor, almost never. The broken reply comes from the website’s server, so restarting your router or your computer will not help. The one exception is cookies: Cloudflare lists oversized headers, often caused by too many cookies, as a cause. If only you see the error, clear the cookies for that site or open it in a private window.
Otherwise, wait a few minutes and reload. If it lasts, tell the site owner and include the Ray ID shown at the bottom of the error page.
If you own the site, it is on your side. Something on the origin is closing connections, crashing, or sending headers Cloudflare will not accept. Upgrading your Cloudflare plan will not change that. The rest of this guide is for you.
How I reproduced error 520 (and what I measured)
Most error 520 guides list causes without ever making the error happen. I wanted to see what a 520 really looks like from both sides, so I built a fresh test server and broke it on purpose. It was a throwaway VPS that I deleted afterwards, running WordPress on a test domain proxied through Cloudflare’s Free plan.

Nginx has a special status code, 444, that tells it to close the connection without sending anything back: no status line, no headers, no body. That is exactly the kind of empty reply Cloudflare describes for error 520, and some Nginx security snippets use it to drop unwanted requests. I added this line to the test site’s Nginx config, for one test path only:
location = /cf520 { return 444; }
Then I requested that path through Cloudflare three times from my PC. All three came back as 520, and fast: 0.27, 0.20 and 0.22 seconds. As soon as the server hung up without answering, Cloudflare showed the error.

On the server, the picture was very different from what a site owner usually expects. The access log recorded the request with status 444 and 0 bytes sent. The site’s error log had no line for it at all; the only entries there were unrelated requests for missing files.
A request made on the server itself, straight to Nginx, failed with curl error 56, “unexpected eof while reading”: the connection was closed before any response arrived. Over plain HTTP, curl reports the same situation as error 52, “Empty reply from server”.

That is the main lesson of the test: a 520 caused by a closed connection may leave nothing in your error log. If you only check the error log, you can miss it. The access log, with its status and byte count, is where it shows up.
Why a dead PHP-FPM gave 502, not 520
Many guides say a crashed PHP application causes error 520. I tested the common Nginx version of that: Nginx sending a request to a PHP-FPM socket that does not exist, which is what you get when PHP-FPM has stopped or crashed. This line points one test path at a dead socket:
location = /cf502 { include fastcgi_params; fastcgi_pass unix:/tmp/cflab-none.sock; }
The result through Cloudflare was 502 Bad Gateway, not 520. Nginx itself was still running, so when it could not reach PHP it sent back a proper HTTP response with a 502 status line. Cloudflare kept that status and answered with 502 Bad Gateway, not with its 520 “unknown error”.

So on an Nginx server, problems behind Nginx usually mean 502: PHP-FPM stopped, a PHP child that crashed or was killed, or a backend that closed the connection early. Nginx notices and answers with a proper error.
A 520 needs Nginx itself to send nothing usable: an Nginx worker that crashes in the middle of a request, a connection closed on purpose with 444, a reply without a valid status line, or headers Cloudflare refuses. On Apache with PHP running inside Apache (mod_php), a PHP crash takes the Apache process down with it, and that does end in a 520. Knowing this narrows the search a lot.
520 vs 521 vs 522 vs 524 vs 502: which layer broke
I caused several Cloudflare errors on the same server, so I can compare them directly. Timing helps, but with 520 it is not enough on its own:
| Error | What Cloudflare saw | Time in my test | Where to look first |
|---|---|---|---|
| 520 Web server is returning an unknown error | Connection worked, reply was empty or invalid | 0.20 to 0.27 s | Access log (status 444 or 0 bytes), crashes, header size, HTTP/2 to origin |
| 521 Web server is down | Connection refused | 0.21 to 0.26 s | Web server stopped, or a firewall rule that rejects Cloudflare |
| 522 Connection timed out | No reply to the connection attempt | 19.39 to 19.75 s | Firewall dropping Cloudflare IPs, wrong IP in DNS, overloaded server |
| 524 A timeout occurred | Connection worked, but the origin did not finish the response within Cloudflare’s time limit | Not tested in this post | Slow PHP, database or long-running scripts |
| 502 Bad Gateway | A valid HTTP 502 from the origin | Not timed | Nginx cannot reach PHP-FPM or another backend |
520 and 521 both arrive in a fraction of a second, so the code itself is what separates them: 521 means nothing accepted the connection, 520 means something accepted it and then failed to answer properly. A 522 is the slow one, because Cloudflare waits about 19 seconds for a reply that never comes. I tested that in detail in my Cloudflare error 522 guide.
What causes error 520
These are the causes worth checking. I reproduced the first one in the lab; the rest come from Cloudflare’s 520 documentation, which I checked on 21 November 2026 (last updated 16 June 2026).
- The origin closes the connection without a response. An Nginx
return 444rule, or a WAF or bot-blocking rule that drops requests without answering. This is what I reproduced. - The web server process crashes. An Nginx worker or Apache process that dies during a request sends nothing back. Cloudflare’s page says 520 is common with certain PHP applications that crash the origin web server; on Nginx with PHP-FPM, a PHP crash alone usually gives 502 instead, as shown above.
- Headers are too large. Cloudflare’s page gives one limit: headers over 128 KB, often caused by too many cookies. Other guides still quote 8 KB, 16 KB or 32 KB; on the day I checked, 128 KB was the only figure on Cloudflare’s page.
- Empty, malformed or incomplete responses. A reply with no status code, no body, missing response headers, or an origin that does not return proper HTTP error responses.
- A broken HTTP/2 setup at the origin. With HTTP/2 to Origin on, Cloudflare uses HTTP/2 with servers that announce support for it. If the server accepts HTTP/2 but does not handle it correctly, Cloudflare returns 520.
- Authenticated Origin Pulls turned on in Cloudflare, but the origin is not set up to match. Cloudflare lists this mismatch as a separate cause.
- A firewall or security plugin blocking Cloudflare’s IP addresses. Cloudflare lists this too. A rule that lets the connection open and then cuts it behaves like my 444 test; a rule that ignores the traffic gives a 522 instead, and one that refuses it gives a 521.
You may also read that error 520 comes from a “TCP idle timeout shorter than 300 seconds” and that you should raise keepalive to 305 seconds or more. That advice is in several other guides, but it is not on Cloudflare’s current error 520 page, so I would not change keepalive settings because of a 520 unless your logs point there.
How to fix error 520 on Nginx, step by step
Every command below says where to run it and what it does. Only the ones marked “changes” modify anything. Replace example.com with your domain and /path with the page that shows the error. The paths shown are aaPanel’s; on a standard Nginx install, the logs are usually in /var/log/nginx/ and the binary is just nginx.
Step 1: Confirm the 520 and note the time and Ray ID
▶ On your own computer, in Windows cmd (not PowerShell). On Mac or Linux, use curl instead of curl.exe, /dev/null instead of NUL, and ; instead of & between the three commands:
curl.exe -s -o NUL -w "%{http_code} %{time_total}\n" https://example.com/path & curl.exe -s -o NUL -w "%{http_code} %{time_total}\n" https://example.com/path & curl.exe -s -o NUL -w "%{http_code} %{time_total}\n" https://example.com/path
What it does: requests the page through Cloudflare three times and prints the status code and total time for each. It changes nothing. A 520 that appears in well under a second, as in my test, means the server answered quickly with nothing usable. Write down the time, and copy the Ray ID from the error page in your browser; you will need both to find the request in your logs.
Step 2: Ask the origin directly, skipping Cloudflare
▶ On the server (SSH terminal):
curl -sSk -o /dev/null -D - --http1.1 --resolve example.com:443:127.0.0.1 https://example.com/path
What it does: sends the same request to the web server on this machine, skipping DNS and Cloudflare, and prints only the response headers (-S makes curl still print errors). It changes nothing.
If you see a normal status line and headers, Nginx is answering and the problem is in what it sends (header size, HTTP/2) or in what happens only for Cloudflare’s requests. If curl prints an error such as 56 “unexpected eof” or 52 “Empty reply from server”, the server is closing the connection without answering, exactly like my 444 test.
Step 3: Find the request in the access log
▶ On the server (SSH terminal):
grep -E '" (444|499|5[0-9][0-9]) ' /www/wwwlogs/example.com.log | tail -n 20
What it does: shows the last 20 requests in the site’s access log that ended with status 444, 499 or any 5xx. It changes nothing.
A line for your page with 444, or with 0 bytes after the status, means Nginx closed the connection on purpose; go to step 5. A 499 means Cloudflare gave up waiting first, which usually goes with a 524, not a 520. A 502 or 504 means Nginx answered but its backend failed, and Cloudflare normally shows that code, not 520. If you find no line at all for the failing request, the Nginx worker may have crashed before it could log it; step 4 covers that.
Step 4: Check the error logs for crashes
▶ On the server (SSH terminal):
tail -n 50 /www/wwwlogs/example.com.error.log; /www/server/nginx/sbin/nginx -T 2>/dev/null | grep -E '^\s*error_log'
What it does: shows the last 50 lines of the site’s Nginx error log, then lists every error log Nginx writes to, so you know where else to look. It changes nothing.
Look in the main Nginx error log for worker process ... exited on signal around the time of the 520: that is an Nginx worker crashing, often in a third-party module such as a WAF, and it gives exactly the empty reply Cloudflare reports as 520.
Lines like upstream prematurely closed connection or upstream sent too big header point at PHP or another backend, and on Nginx those end in 502, not 520. Remember my test: a deliberate close left nothing in the error log, so an empty error log does not rule out the origin.
Step 5: Look for rules that close connections
▶ On the server (SSH terminal):
/www/server/nginx/sbin/nginx -T 2>/dev/null | grep -n 'return 444'
What it does: prints the full Nginx configuration Nginx is really using and shows every line that closes connections with 444, with its line number. It changes nothing.
If a rule matches the failing path, or blocks a user agent, country or IP range that includes Cloudflare’s traffic, that rule is your 520. A return 444 inside a default_server block is different: it only drops requests for unknown host names, so leave that one alone. Fix or remove the rule that matches in the site’s config (on aaPanel: Website, your site, Config or URL rewrite), then test and reload:
▶ On the server (SSH terminal): (changes the Nginx config)
/www/server/nginx/sbin/nginx -t && /www/server/nginx/sbin/nginx -s reload
What it does: checks the configuration for errors, and only if the check passes, reloads Nginx so the change takes effect without dropping open connections.
Also make sure no firewall or security tool on the server is cutting off Cloudflare. Check your server firewall, aaPanel’s Nginx firewall or WAF, and any security plugin for rules that block Cloudflare’s published IP ranges, and allow those ranges. A tool that drops Cloudflare completely gives 522, but one that lets the connection open and then cuts it can give 520.
Step 6: Measure the response header size
▶ On the server (SSH terminal):
curl -sSk -o /dev/null -D - --resolve example.com:443:127.0.0.1 https://example.com/path | wc -c
What it does: prints the size in bytes of all the response headers your server sends for that page. It changes nothing. Normal pages send a few hundred bytes to a few kilobytes. Anything close to 128 KB (131,072 bytes) is a problem, usually from a plugin or app that sets many cookies or long custom headers. On the request side, clearing the site’s cookies in your browser is the quick test: if the 520 disappears for you, oversized cookies were the cause.
Step 7: Rule out HTTP/2 to Origin and Authenticated Origin Pulls
If the origin answers fine in step 2 but Cloudflare still shows 520, check the settings that only affect Cloudflare’s own connection. Cloudflare’s 520 page suggests turning off HTTP/2 to Origin under Speed, Settings, Protocol Optimization as a test (this changes a Cloudflare setting; turn it back on once you fix the server’s HTTP/2 setup). If you use Authenticated Origin Pulls, make sure the server is really configured for them, or turn the feature off.
Step 8: Still 520? Send your host or Cloudflare the evidence
Cloudflare asks for the full URL, the Ray ID from the 520 page, the output of https://example.com/cdn-cgi/trace, and two HAR files from your browser’s developer tools: one with Cloudflare on and one with it temporarily off. Add the access log line and the curl output from steps 2 and 3. With that, a host cannot simply say “it is Cloudflare”.
Check that it is fixed
Run the three requests from step 1 again. You should see 200 (or a normal redirect) instead of 520, every time. In my lab the 520 came from a rule I had added on purpose; I did not record a separate timed run after removing it, so I have no “after” number to show here.
Fixing error 520 on Apache or shared hosting
On Apache, a 520 usually means a crash in the PHP module or an Apache child process, or a security module that drops requests. Check Apache’s error log (often /var/log/apache2/error.log or /var/log/httpd/error_log) around the time of the error for Segmentation fault or exit signal, and check .htaccess and ModSecurity for rules that block Cloudflare’s IP ranges. Steps 1, 2, 6 and 8 above work the same on Apache.
On shared hosting you cannot see the server logs, so open a ticket with the Ray ID, the time and the curl result from step 1, and ask them to check their logs and their firewall for that request. If your host cannot help with errors like this, a small VPS gives you full access to the logs; I tested Vultr, Hetzner and DigitalOcean with real numbers.
Should you pause Cloudflare or switch to DNS only?
Cloudflare lists both as a temporary workaround: set the DNS record to DNS only (grey cloud) or pause Cloudflare for the site. It is useful for one thing, a quick test. If the site works with the grey cloud, the origin can serve normal visitors and the problem is specific to how Cloudflare connects (HTTP/2, Authenticated Origin Pulls, rules that only hit Cloudflare’s IPs).
Do not leave it like that. With DNS only, your server’s IP address is public, and you lose Cloudflare’s caching and protection. Switch back to proxied as soon as you have tested. My Cloudflare settings for WordPress guide covers the settings to check once the site is back.
Does error 520 hurt SEO?
A short 520 is unlikely to do lasting damage. Google’s documentation says 5xx server errors make Googlebot slow down crawling, and that indexed URLs that keep returning server errors are eventually dropped from the index. Fix it the same day, especially if every page is affected.
How to prevent error 520
- Watch your access log, not only the error log. A sudden run of 444 or 0-byte responses is an early warning, and it may be the only trace a 520 leaves.
- Keep security rules away from Cloudflare’s traffic. If you block bots or countries in Nginx, make sure the rule looks at the real visitor IP, not Cloudflare’s. Cloudflare explains how to restore visitor IPs in Nginx and Apache, and its IP ranges are published.
- Keep cookies and headers small. Remove plugins that set dozens of cookies, and test header size after installing anything new.
- Update Nginx modules, WAF rules and PHP carefully. A crashing Nginx module gives 520, and on Apache with mod_php so does a crashing PHP extension. Test updates on staging first.
- Give the server enough memory. A server that runs out of memory starts killing processes mid-request, and if the killed process is the web server itself, Cloudflare sees an empty reply. A Hetzner or Vultr plan with more RAM can fix the cause instead of the symptom.
- Know what Cloudflare is doing for you. cf-cache-status explained shows how to check which requests even reach your server, and my Cloudflare settings for WordPress guide covers the rest of the setup.
Error 520 FAQ
What does error code 520 mean?
It means Cloudflare reached your origin server, but the reply it got back was empty, unknown or unexpected, so Cloudflare could not pass a normal page to the visitor. It is a Cloudflare-only code, not a standard HTTP status.
How do I fix error code 520?
If you are a visitor, wait a few minutes and reload, or clear the cookies for that one site. If you own the site, look at your server: find the failing request in the web server’s access log, check the error logs for crashes, test the origin directly with curl, and check header size and HTTP/2 to Origin. The step-by-step section above has the commands.
Is error 520 permanent?
No, but it does not go away by itself if the cause is a setting. A 520 from a crash or overload can clear on the next request. A 520 from a config rule, oversized headers or a broken HTTP/2 setup stays until you fix that cause. In my lab, every request to the test path returned 520 while the rule was in place.
Is Cloudflare blocking me when I see error 520?
No. A Cloudflare block looks different: you get an Access denied page or a security check, such as error 1020. Error 520 means the website’s own server sent Cloudflare a reply it could not use.
Can cookies cause error 520?
Yes. Cloudflare’s 520 page lists headers over 128 KB, often caused by too many cookies, as a cause. If the error happens for you but not in a private window, clear that site’s cookies and try again.
Why do I see error 520 only on my phone or in one browser?
Usually because that device sends something the others do not, most often a large pile of cookies for the site. Clear the site’s data on that device or try a private window. If every device gets 520, the problem is on the server.
What is the Ray ID on the 520 page?
It is the ID Cloudflare gives that single request, printed at the bottom of the error page. Send it to the site owner, your host or Cloudflare Support with the time of the error, so they can find the exact request in their logs.
Can a WordPress plugin cause error 520?
It can, indirectly. A plugin that crashes the web server process, sends huge or broken headers, or sets a large number of cookies can end in a 520. When PHP-FPM itself is down, Nginx answers with 502 instead, as my test showed, and an ordinary PHP fatal error usually gives a 500.
Is error 520 the same as 502 Bad Gateway?
No. A 502 is a proper HTTP response: some server sent a status line saying the gateway failed, and Cloudflare passes that code on. A 520 means Cloudflare got no usable response at all. In my lab, the same Nginx server gave 502 for a dead PHP-FPM socket and 520 for a closed connection.
