Error Code 521 on Cloudflare and How to Fix It
You hit Publish, open the page in a fresh tab, and get a Cloudflare screen that says “Web server is down.” You try the homepage. Same screen. You check your hosting dashboard, only to find that it shows the server is up and running normally.
Error code 521 occurs when Cloudflare attempts to connect to your website’s origin server, but the server rejects the connection. The origin is where your site runs, usually at your hosting provider. It can be online while its web service has stopped accepting traffic. A firewall can refuse the connection, too.
Table of Contents
- Start with the request that failed
- Check whether your web server is running
- Match the origin port to your Cloudflare settings
- Look for a firewall blocking Cloudflare
- Test the origin directly and check DNS
- Get your host the details that matter
Start with the request that failed
If you’re visiting someone else’s site, give it a minute and reload once. If the error keeps coming back, tell the site owner which page you were trying to open. They or their hosting provider can investigate the connection.
If it’s your site, write down the full URL, the time and time zone, and the Cloudflare Ray ID if it appears at the bottom of the error page. For a shop or a member site, note what you did just before it failed. “I opened the checkout page after adding something to my cart” gives your host a request they can try to reproduce.
Now check the scope. Say the homepage loads, but shop.example.com shows 521. Start with the server and settings for the shop. If one page on the same hostname works and another fails, the working page may be cached. In your browser’s Network tab, a CF-Cache-Status: HIT response header confirms Cloudflare served that page from its cache. Pages that need a fresh response from the origin can still fail.
Check whether your web server is running
The web service is where I’d start, especially after a deployment, reboot, or round of hosting maintenance. On managed hosting, look for the site’s service status and error logs in your hosting panel. If you manage the server, see whether Nginx, Apache, or whatever serves your site is accepting connections.
On a Linux server that uses systemd and runs Nginx, systemctl status nginx shows the service’s current state. Run sudo ss -ltnp to see which processes are listening for TCP connections. Check the address and port that receive your site’s web traffic. If a reverse proxy handles incoming connections on that server, look for its listener.
If the service is down, read the startup errors before restarting it. Say Nginx stopped after you edited the site’s configuration. On that server, sudo nginx -t can tell you whether it can load the configuration and the files it references. If the test turns up a missing certificate file or a typo, fix it and run the test again before bringing the service back up. That first startup error may explain why every attempt to start the service ends the same way.
Match the origin port to your Cloudflare settings
For a typical HTTPS visit, Cloudflare’s Flexible mode connects to the origin over HTTP on port 80. Full and Full (strict) connect over HTTPS on port 443. Check SSL/TLS → Overview in the Cloudflare dashboard for your site’s encryption mode. If you’ve set an Origin Rule that overrides the destination port for the failing request, check the port named in the rule.
Picture a site that’s been serving traffic on port 80 for months. You upload a certificate, switch to Full (strict), and suddenly every secure page shows 521. The web server still needs to load that certificate and listen for HTTPS connections. Check the HTTPS settings for the affected domain in your hosting panel or server configuration. If the origin already listens on the right port, check whether your hosting firewall lets Cloudflare through to it.
With Full (strict), the origin also needs a valid certificate that covers the hostname. A certificate issued by a publicly trusted authority or Cloudflare Origin CA can meet that requirement. If your host manages HTTPS for you, ask them to check that the server actually presents the certificate for that domain on the expected port.
Look for a firewall blocking Cloudflare
The origin sees connections from Cloudflare’s IP addresses. Many visitors’ requests can arrive from the same Cloudflare address, so a security tool that judges traffic by the connecting IP may see one very busy source. A rule that automatically blocks busy addresses can end up refusing Cloudflare’s connections.
Say a flash sale is going smoothly until your host’s connection limit kicks in. A customer sends you a screenshot of a 521, yet the product page opens fine on your phone. If the rule has blocked only some Cloudflare addresses, both experiences are possible. Check the security logs at the time the customer saw the error and look for a block or rate-limit entry.
Check the provider’s network firewall and any firewall or security software on the server. Use Cloudflare’s published IPv4 and IPv6 ranges when adjusting rules for the web ports your site uses. If Cloudflare is already on an allowlist, look for a separate rate limiter that could still refuse the connection.
Test the origin directly and check DNS
After a hosting move, compare the failing hostname’s A or AAAA record in Cloudflare with the address your current host gave you. Check both records if your host gave you IPv4 and IPv6 addresses. If you use a CNAME, verify its target. A public DNS lookup for a proxied hostname returns Cloudflare addresses, so use the record’s value in your dashboard for this check. An old address can lead to a server that still exists and refuses connections.
From a network that’s allowed to reach the origin, you can test it directly with curl. Replace example.com and 203.0.113.10 with your hostname and origin IP. The --resolve option sends the request to the specified address while keeping the hostname, which matters when several sites share one IP. For an HTTP origin, use port 80 and an http:// URL.
curl -v --noproxy '*' --connect-timeout 5 \
--resolve example.com:443:203.0.113.10 https://example.com/ -o /dev/null
If curl reports “Connection refused,” check the listener and any firewall rejection rules for that address and port. An HTTP response shows the origin accepted your connection from where you ran the test. If Cloudflare still gets a refusal, check whether it’s reaching the same address you tested and whether your security rules treat Cloudflare’s traffic differently.
You might see a certificate warning if the origin uses Cloudflare Origin CA and your machine lacks that authority in its trust store. Getting that warning still tells you that the connection reached the TLS stage. If your origin accepts traffic only from Cloudflare’s addresses, ask your host to test it from an authorized network.
Get your host the details that matter
If the error keeps coming back, send your host the request details you collected and tell them what changed before the first failure. Timing helps here. If 521 appears every night just after 2 a.m., mention the pattern so your host can check what the web service and firewall were doing around then. If it started right after a migration, ask them to confirm the new origin address and whether it accepts Cloudflare connections on the expected port.
Ask your host to check the logs for any load balancer or proxy in front of the web server, too. A connection refused there may never reach the web server’s access log. For intermittent failures, ask whether the service restarted at the time you reported and what the system logged immediately beforehand. It’s easy to miss a ten-second outage if you check the server after it’s already recovered.
Once the fix is in, open the exact page that failed at its regular public URL. If the error usually appeared during a nightly backup, open that page while the next backup is running, too. That’s the check I’d trust when a site has a habit of coming back on its own.
