Cloudflare Error 521 (Web Server Is Down): Causes and a Tested Fix
Error 521 (Web server is down) means Cloudflare tried to connect to your web server and the server refused the connection. Cloudflare is working and so is the visitor’s browser. The problem is on the origin server (the real server behind Cloudflare): the web server software is stopped or crashed, nothing is listening on the port Cloudflare uses, or a firewall is rejecting Cloudflare’s IP addresses.
If you are only visiting a site that shows error code 521, there is nothing to fix on your side: wait a few minutes and reload. If it is your site, the fix is on your server. Below I show how I caused error 521 on purpose on an Nginx server behind Cloudflare, two different ways, how fast it failed, what aaPanel did on its own when I stopped Nginx, and the commands that find and fix the 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 on the server itself
- There are no affiliate links in this guide. How I test: how we review
Table of Contents
What error code 521 means
Error 521 is a Cloudflare status code, not a standard HTTP one. Cloudflare’s own error 521 page says it happens when the origin web server refuses connections from Cloudflare, and names two common causes: the web server application is offline, or Cloudflare’s requests are blocked. The browser page calls it Web server is down, which is why searches for “web server is down error code 521” land on the same problem.
In plain words: Cloudflare knocked and the server slammed the door. That is different from error 522, where nobody answers the door at all, and from error 520, where the door opens but what comes back is empty or broken.

The red Host box means Cloudflare is pointing at your server, not at itself and not at the visitor. Some guides call 521 a timeout. It is not: a refusal comes back almost instantly, as the timings below show. The timeout error is 522.
Is error 521 your fault? Visitor vs site owner
If you are a visitor, no. The website’s server is refusing Cloudflare, so clearing your cache, restarting your router or switching browsers will not change anything. Searches like “error 521” on a game, streaming app or shopping site are the same story. Wait a few minutes and reload. If it lasts, tell the site owner and include the Ray ID, the short reference code Cloudflare prints at the bottom of the error page.
If you own the site, it is on your side. Either the web server is not running, it is not listening where Cloudflare connects, or something on the server is turning Cloudflare away. Upgrading your Cloudflare plan will not fix any of those. The rest of this guide is for you.
How I reproduced error 521 (and what I measured)
Most error 521 guides list causes without ever making the error happen. I wanted to see what a 521 really looks like from both sides, so I built a fresh test server and broke it on purpose, two ways. It was a throwaway VPS that I deleted afterwards, running WordPress on a test domain proxied through Cloudflare’s Free plan.

Test 1: Nginx stopped
First I stopped Nginx with aaPanel’s own service script, waited two seconds, checked which ports were listening, and asked the site for a small test file from the server itself, skipping Cloudflare:
/etc/init.d/nginx stop; sleep 2; ss -ltn | grep -E ':(80|443) '; curl -sSk -o /dev/null -w "%{http_code}\n" --resolve filecafe.site:443:127.0.0.1 https://filecafe.site/cf-lab.txt
Nginx reported “Stoping nginx… done” (aaPanel’s spelling), the port check printed nothing, because nothing was listening on 80 or 443 any more, and curl failed with error 7, Connection refused, with status 000. That is the server-side picture of a 521: the machine is up, but no web server accepts the connection.

Then I requested the same file through Cloudflare three times from my PC. All three came back as 521, in 0.26, 0.21 and 0.23 seconds. Cloudflare reported the refusal right away, about as fast as a normal page loads.

What aaPanel did on its own
None of the top-ranking guides I read mention this. When I went to start Nginx again a little later, it was already running. aaPanel’s service script answered “nginx (pid 45238) already running”, port 443 was listening again, and the test file returned 200. I had not started it. By then the site was already loading again in my browser.

Two practical lessons come out of this. First, on an aaPanel server a stopped or crashed Nginx can come back on its own, so a 521 caused by the web server going down may last only a short while and look random to you and your visitors. If you see short 521s that come and go, check whether the web server keeps stopping (step 4 below), instead of assuming Cloudflare is flaky.
Second, it meant I could not take a browser screenshot of a 521 just by stopping Nginx: the site came back before I could. So for the browser page I used the second cause instead.
Test 2: a firewall that rejects Cloudflare
With Nginx running normally, I added firewall rules that refuse connections on port 443 from Cloudflare’s published IPv4 ranges, using iptables REJECT with a TCP reset (the server answers “no” instead of staying silent). Everyone else could still reach the server; only Cloudflare was turned away.
Cloudflare again answered with 521, in 0.23, 0.22 and 0.20 seconds. The browser screenshot at the top of this guide was taken in this state. So from Cloudflare’s side, “the web server is stopped” and “a firewall refuses me” look exactly the same: a fast 521.

After I deleted the REJECT rules, the same three requests returned 200 in 1.95, 0.66 and 0.21 seconds. The first request was clearly slower than the other two; I did not measure what caused that, so I will not guess. What matters is that nothing else had to change: no purge and no Cloudflare setting. As soon as Cloudflare could connect, the 521 was gone.
In another test on the same server, the same rules used DROP instead of REJECT (silently ignoring the packets). Cloudflare then showed 522 instead, after about 19 seconds. That one word is the whole difference between 521 and 522; I covered the DROP case in my Cloudflare error 522 guide.
521 vs 520 vs 522 vs 524: which layer broke
I caused several Cloudflare errors on the same server, so I can compare them directly:
| Error | What Cloudflare saw | Time in my test | Where to look first |
|---|---|---|---|
| 521 Web server is down | Connection refused | 0.20 to 0.26 s | Web server stopped or crashed, nothing on port 443/80, or a firewall REJECT rule |
| 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 |
| 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 |
521 and 520 both fail in a fraction of a second, so the code is what separates them: 521 means nothing accepted the connection, 520 means something accepted it and then failed to answer properly (my Cloudflare error 520 guide shows that case). A 522 is the slow one. If you can time how long the error takes to appear, you already know which layer to check.
What causes error 521
These are the causes worth checking. I reproduced the first two in the lab; the rest come from Cloudflare’s 521 documentation, which I checked on 21 November 2026 (last updated 23 April 2026).
- The web server is stopped or has crashed. Nginx, Apache or LiteSpeed is not running, so nothing accepts connections. This includes a web server killed because the server ran out of memory, and a failed restart after a config change. I reproduced this one.
- A firewall or security tool rejects Cloudflare’s IP addresses. An iptables, UFW or panel firewall rule, or a security tool that bans IPs, refuses Cloudflare’s connections. Behind Cloudflare, all your visitors arrive from Cloudflare’s IPs, so a tool that bans “too many requests from one IP” can end up banning Cloudflare. I reproduced the firewall part with REJECT.
- Nothing is listening on the port your SSL/TLS mode uses. Cloudflare’s page is specific: port 80 for Flexible, port 443 for Full and Full (strict). If your Cloudflare mode is Full but the site has no HTTPS set up on the server, and no other site on that server listens on 443 either, Cloudflare finds nothing on 443 and shows 521. If another site does listen on 443, the connection is accepted and you usually get a different error (often 526 in Full (strict)) or the other site’s page instead.
- The origin does not support HTTPS in Full or Full (strict) mode. Cloudflare says to make sure the origin supports HTTPS, or to install a Cloudflare Origin Certificate or another certificate that meets the mode’s requirements. (If something does answer on 443 but the certificate or handshake is wrong, Cloudflare usually shows 525 or 526 instead.) I reproduced both errors in my error 525 and error 526 guides.
- Rate limiting of Cloudflare’s IPs. Cloudflare lists blocked or rate-limited Cloudflare IPs as a separate check, for example a host-level rate limit or a hosting provider’s own protection.
How to fix error 521 on Nginx and aaPanel, 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. The paths shown are aaPanel’s; on a standard Nginx install, the binary is just nginx, the service command is systemctl, and the logs are usually in /var/log/nginx/.
Step 1: Confirm the 521 and how fast it fails
▶ 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 -sS -o NUL -w "%{http_code} %{time_total}\n" https://example.com/ & curl.exe -sS -o NUL -w "%{http_code} %{time_total}\n" https://example.com/ & curl.exe -sS -o NUL -w "%{http_code} %{time_total}\n" https://example.com/
What it does: requests your homepage through Cloudflare three times and prints the status code and total time for each (-S makes curl still show an error if one happens). It changes nothing. A 521 that comes back in well under a second, as in my tests, confirms a refusal. If instead it takes about 19 seconds and says 522, you have a different problem; see my error 522 guide. Note the time and copy the Ray ID from the error page in your browser.
Step 2: Check whether the web server is running and listening
▶ On the server (SSH terminal):
pgrep -a nginx; ss -ltnp | grep -E ':(80|443) '
What it does: lists any running Nginx processes, then the programs listening on ports 80 and 443. It changes nothing (run it as root or with sudo, otherwise ss may not show the program names). If the first part prints nothing, Nginx is not running. On Apache, use pgrep -a apache2 (or httpd) instead.
You want to see nginx listening on :443 (and :80). If the list is empty, the web server is down: go to step 4. If Nginx listens on 80 but not 443 while Cloudflare is set to Full or Full (strict), no site on the server has HTTPS: go to step 5. If your domain has an AAAA (IPv6) record, also check for a [::]:443 line, because Cloudflare can connect to your server over IPv6.
Step 3: Test the origin directly, skipping Cloudflare
▶ On the server (SSH terminal):
curl -sSk -o /dev/null -w "%{http_code}\n" --resolve example.com:443:127.0.0.1 https://example.com/
What it does: sends a request to the web server on this machine for your domain, skipping DNS and Cloudflare, and prints the status code. It changes nothing.
Connection refused (curl error 7, status 000) means the web server is not accepting connections on 443, exactly like my test 1. A 200 or a 301/302 means the web server is fine locally, so if Cloudflare still shows 521, something is refusing only Cloudflare’s connections: go to step 6.
Step 4: Start the web server and find out why it stopped
▶ On the server (SSH terminal): (changes the running services)
/www/server/nginx/sbin/nginx -t && /etc/init.d/nginx start
What it does: checks the Nginx configuration for errors, and only if the check passes, starts Nginx. On a standard install, use nginx -t && systemctl start nginx. If the test fails, it prints the file and line with the problem; a broken config left behind after an edit is a common reason Nginx will not come back after a restart.
Starting it fixes the symptom. To find the cause, look at the logs and at memory:
▶ On the server (SSH terminal):
/www/server/nginx/sbin/nginx -T 2>/dev/null | grep -E '^\s*error_log'; free -m; dmesg -T | grep -i -E 'out of memory|killed process' | tail -n 5
What it does: lists every error log Nginx writes to (open the main one with tail -n 50 and the path it shows), shows free memory, and prints the last kernel messages about processes killed because the server ran out of memory (the kernel’s out-of-memory killer, often shortened to OOM). It changes nothing. dmesg needs root or sudo on Ubuntu, and its messages are lost after a reboot; on a standard install, journalctl -u nginx shows the service’s own history too.
A line that names nginx or php-fpm as the killed process means the server needs more memory or fewer heavy processes. On aaPanel, remember that Nginx may already be running again by the time you look, so a short 521 with an out-of-memory line in dmesg is still worth fixing.
Step 5: Make sure the right port has a working site
Check your Cloudflare SSL/TLS mode (SSL/TLS, Overview). With Full or Full (strict), Cloudflare connects on port 443 and your site must have HTTPS set up on the server. With Flexible, it connects on port 80. On aaPanel, open Website, your site, SSL: if no certificate is deployed, there is no HTTPS server for the site. If no other site on the server has HTTPS either, Nginx does not listen on 443 at all and Cloudflare gets refused.
The proper fix is to install a certificate on the server (a Let’s Encrypt certificate from aaPanel, or a free Cloudflare Origin Certificate) and keep Full (strict). At least one popular video in the search results suggests switching Cloudflare to Flexible when the server has no certificate. That only moves Cloudflare to port 80 without encryption between Cloudflare and your server, and it often creates redirect loops. My Cloudflare settings for WordPress guide explains which SSL mode to use.
Step 6: Look for firewall rules that reject Cloudflare
▶ On the server (SSH terminal):
iptables -L -n -v --line-numbers | grep -E "^Chain|REJECT|DROP"; ufw status numbered
What it does: lists every firewall chain with its REJECT and DROP rules, their packet counters and line numbers, then UFW’s rule list if you use UFW. It changes nothing (run as root or with sudo). Listing all chains matters: UFW and many security tools put their rules in their own chains, not directly in INPUT.
Look for a REJECT rule that matches a Cloudflare range, such as 104.16.0.0/13, 172.64.0.0/13 or 173.245.48.0/20, or a broad rule that rejects everything on 80 or 443. Run it twice, a minute apart, while the site shows 521: a counter that keeps going up on a Cloudflare range is your answer. A DROP rule on those ranges would give 522, not 521. On aaPanel, also check the Security page for blocked IPs and port rules, and any Nginx firewall or web application firewall (WAF) you installed there.
▶ On the server (SSH terminal): (changes the firewall)
iptables -D INPUT 3
What it does: deletes rule number 3 from the INPUT chain. Use the chain name and line number from your own listing, and list the rules again right before you delete, because the numbers shift after every change. If the rule belongs to UFW, remove it with UFW instead: ufw delete NUMBER, using the number from ufw status numbered. If the rule belongs to a security tool, allow Cloudflare in that tool’s own settings, or it will add the ban again. Rules saved with netfilter-persistent (the package that reloads iptables rules at boot) also come back after a reboot unless you remove them from the saved rules.
▶ On the server (SSH terminal): (changes the firewall, UFW only)
for ip in $(curl -sSL https://www.cloudflare.com/ips-v4); do ufw allow proto tcp from $ip to any port 80,443; done
What it does: downloads Cloudflare’s current IPv4 list and adds an allow rule for ports 80 and 443 for each range (run it with sudo). Run it again with ips-v6 if your server has IPv6. UFW checks rules from the top, so delete any older rule that denies or rejects 80 or 443 first, as above. My error 522 guide has more on firewall clean-up.
Step 7: Still 521? Send your host the evidence
If the web server runs, listens on the right port, answers locally and your firewall is clean, the refusal may be happening at your host, for example a network firewall or protection system in front of your server. Send your host the time of the error, the Ray ID, the result of step 1 and the output of steps 2, 3 and 6. Cloudflare’s 521 page also points you to its Community troubleshooting guide for error 521.
Check that it is fixed
Run the three requests from step 1 again. You should see 200 (or a normal redirect) instead of 521, every time. In my lab, the requests after removing the REJECT rules returned 200 in 1.95, 0.66 and 0.21 seconds, with the first one slower than the rest. If the 521 comes back after a while, the web server is stopping again or a security tool is re-adding its ban, so go back to steps 4 and 6.
Fixing error 521 on Apache or shared hosting
On an Apache server you manage yourself, the steps are the same idea.
▶ On the server (SSH terminal):
systemctl status apache2; apachectl configtest
What it does: shows whether Apache is running and why it last stopped, then checks the Apache configuration for errors. It changes nothing. On CentOS, AlmaLinux and similar systems the service is called httpd. If the test passes, start Apache with systemctl start apache2 (this changes the running services). The ss, curl and firewall commands above work the same on Apache. Also check .htaccess and ModSecurity for rules that deny Cloudflare’s IP ranges.
On shared hosting you cannot see the firewall or the service, so open a ticket with the Ray ID, the time and the result of step 1, and ask the host to check that the web server is running for your account and that their firewall allows Cloudflare’s ranges. If your host cannot help with errors like this, a small VPS gives you full control; I tested Vultr, Hetzner and DigitalOcean with real numbers.
Is error 521 permanent?
No. A 521 lasts exactly as long as its cause. In my lab, removing the firewall rule brought the site back on the very next request, and on aaPanel a stopped Nginx came back by itself shortly after. A 521 that never goes away usually means a firewall rule or a missing HTTPS setup that someone has to fix; one that comes and goes usually means a web server that keeps crashing and restarting.
Should you switch to DNS only (grey cloud)?
As a quick test, yes; as a fix, no. If the site works with the record set to DNS only, your server accepts direct visitors and the problem is specific to Cloudflare’s connections: a firewall or rate limit that hits Cloudflare’s IPs, or a missing HTTPS listener in Full mode. If the site fails with DNS only too, the web server itself is down.
Switch back to proxied as soon as you have tested. With DNS only, your server’s IP address is public and you lose Cloudflare’s caching and protection. cf-cache-status explained shows how to check what Cloudflare caches once the site is back.
Does error 521 hurt SEO?
A short 521 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 521
- Monitor through Cloudflare, not only the server. An uptime check that loads your real domain catches a 521 that a check on the server’s IP would miss, and it records the short ones you would never see yourself.
- Keep Cloudflare’s ranges allowed everywhere. OS firewall, panel firewall and any security tool that bans IPs. Restore real visitor IPs so those tools ban visitors, not Cloudflare; Cloudflare explains how to restore visitor IPs for Nginx and Apache.
- Test before you reload. Run
nginx -tafter every config change, so a typo never leaves the web server stopped. - Give the server enough memory. A server that runs out of memory kills processes, and if it kills the web server, Cloudflare sees a refusal. A Hetzner or Vultr plan with more RAM fixes the cause instead of the symptom.
- Keep HTTPS working on the origin. Renew certificates before they expire and keep Cloudflare on Full (strict); my Cloudflare settings for WordPress guide covers the rest of the setup.
Error 521 FAQ
What does error code 521 mean?
It means Cloudflare tried to connect to the website’s own server and the server refused the connection. Cloudflare shows it as Web server is down. It is a Cloudflare-only code, not a standard HTTP status.
How do I resolve error 521?
If you are a visitor, wait a few minutes and reload; the problem is on the website’s server. If you own the site, check that the web server is running and listening on port 443 (or 80 with Flexible SSL), then check the firewall for rules that reject Cloudflare’s IP ranges. The step-by-step section above has the commands.
Is error code 521 permanent?
No. It lasts exactly as long as the cause. In my lab, the site came back on the next request once the firewall rule was removed. A stopped web server that a panel restarts by itself may give a 521 for only a short time, while a firewall rule keeps it there until you remove it.
Is error 521 my fault?
Not if you are a visitor. Your browser and Cloudflare are both working; the website’s server is refusing the connection. If you own the site, the cause is on your server or in its firewall, not in your Cloudflare plan.
Why is Cloudflare blocking me from my website?
With error 521 it is the other way round: your server, or a firewall in front of it, is blocking Cloudflare. A real Cloudflare block looks different, with an Access denied page or a security check such as error 1020.
What is the difference between error 521 and 522?
521 means the server refused the connection, so it fails fast: 0.20 to 0.26 seconds in my tests. 522 means the connection attempt got no reply, so Cloudflare waits about 19 seconds first. On the same server, the same firewall rules gave 521 with REJECT and 522 with DROP.
Why do I get error 521 when my server is running?
Because running is not enough: the web server must accept Cloudflare’s connections on the right port. A firewall that rejects Cloudflare’s IP ranges, or a site with no HTTPS listener while Cloudflare uses Full or Full (strict), gives 521 even though the machine is up.
Can a WordPress plugin cause error 521?
Not directly. Plugins run only after the web server accepts a connection, so they cause errors such as 500 or 403. A security plugin that writes server firewall rules, or a heavy plugin that makes the server run out of memory and kill the web server, can lead to a 521.
Why am I suddenly getting error 521 on my site?
Something changed on the server side: the web server stopped or failed to restart after an update or a config edit, the server ran out of memory, a certificate or HTTPS setting was removed, or a security tool started banning Cloudflare’s IP addresses. Check those in that order with the steps above.
Should I switch Cloudflare to Flexible SSL to fix error 521?
No. Flexible makes Cloudflare connect on port 80 without encryption, so it can hide a missing HTTPS setup instead of fixing it. Fix the web server or the certificate on your server and keep Full (strict).
