Find out why your server refused Cloudflare's connection
Cloudflare error 521 means your origin server refused the connection when Cloudflare tried to reach it. Cloudflare is up and answering your visitors; the refusal came from your side. Either the web server on the origin isn't running, it isn't listening on the port Cloudflare connects to, or a firewall or security tool is turning away requests from Cloudflare's IP addresses.
Why your server refuses Cloudflare
The web server isn't running
nginx, Apache or the app server stopped or crashed, so nothing accepts connections on the port and the operating system turns each one away.
Cloudflare's addresses are blocked
A firewall, an intrusion tool or a security plugin blocks or rate limits some of Cloudflare's IP ranges. With Cloudflare in front, every visitor's request arrives from those ranges, so one bad rule fails every visitor whose request comes through a blocked address.
Nothing listens on the right port
Cloudflare connects on port 80 in its Flexible mode and on 443 in Full or Full (strict). A server with nothing on the port its mode needs, such as one set up for plain HTTP alone under a Full mode, refuses the connection.
Cloudflare's error 521 guide names a stopped web server application and blocked Cloudflare requests as the two most common causes, and gives the port each encryption mode needs. Cloudflare publishes its address ranges at cloudflare.com/ips.
Check what listens on the server, then connect from outside
# On the origin server: list the processes listening on ports 80 and 443
sudo ss -ltnp '( sport = :80 or sport = :443 )'
# From another machine: connect to the origin's IP address (203.0.113.10 here) on 443, skipping Cloudflare
curl -sv -o /dev/null --connect-to ::203.0.113.10 https://yoursite.com/ 2>&1 | grep -iE 'connected|refused|^< HTTP'
# In Flexible mode, test port 80 instead
curl -sv -o /dev/null --connect-to ::203.0.113.10 http://yoursite.com/ 2>&1 | grep -iE 'connected|refused|^< HTTP'
Read the results
If
ssshows nothing on the port Cloudflare uses, the web server is stopped or bound somewhere else, and starting it or fixing the port in its config ends the 521. If something is listening but the outside request printsConnection refused, look at the firewall on the server and at any network firewall your host runs in front of it. A rule that rejects connections produces exactly this refusal; one that drops them silently leaves Cloudflare waiting instead, which shows up as error 522.If your own direct request gets through but Cloudflare still sees a 521, the block probably targets Cloudflare's addresses alone. Compare the firewall's deny and rate limit rules with the ranges on Cloudflare's list, which also comes as plain text for scripts at ips-v4 and ips-v6.
How to fix Cloudflare error 521
- Start the web server and find why it stoppedRestart the stopped service, then read its log and the system log for the reason, such as a crash, an out-of-memory kill or a config error at startup, so it doesn't stop again.
- Listen on the port Cloudflare connects toMake the server accept connections on 443 for Full or Full (strict), or on 80 for Flexible, and install a certificate on it if Cloudflare connects over HTTPS.
- Allow every Cloudflare address rangeAdd all of Cloudflare's published IPv4 and IPv6 ranges to the allow list of the server's firewall and of any security plugin, and exempt them from limits that count requests per IP.
- Check automatic ban lists tooIf you run a tool that bans addresses on its own, look through its current bans after each 521. It can add a Cloudflare address at any time, long after you fixed the static rules.
Frequently asked questions
Is Cloudflare down when I see error 521?
No. The 521 page comes from Cloudflare, so Cloudflare is answering your visitors. What failed is the hop from Cloudflare to your server, which turned the connection away. Cloudflare's guide starts with making sure the origin web server is responsive.
Why does my site load when I use the server's IP directly?
Your request and Cloudflare's can differ in two ways. Typed into the address bar, an IP address defaults to plain HTTP in Chrome, which connects on port 80, while Cloudflare connects on 443 in Full or Full (strict), so check that 443 answers too. If it does and Cloudflare is still refused, a firewall or security plugin is treating Cloudflare's addresses differently from yours. Cloudflare's 521 guide lists blocked or rate-limited Cloudflare addresses as one of the two main causes.
How do I find out when my server goes down?
A stopped web server takes the site down for every visitor who comes through Cloudflare, so the sooner you hear about it, the shorter the outage. SiteCMD requests your home page every few minutes once you add the site, and it emails you when the site goes down and again once it recovers.
Find out when your server stops answering
- Website reliabilityHear about it when your site goes down, not days later from a customer.
- Cloudflare error 522Find where Cloudflare's packets go unanswered, then fix the firewall, the address or the load behind it.
- Cloudflare error 520Find out why your origin sent Cloudflare an empty or unreadable response, then fix the crash, block or header behind it.
- Is my website down?Tell your own connection apart from a real outage, then trace the error to its cause.