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 521 means the origin web server refused connections from Cloudflare. Bring the origin listener back up, open the port your SSL/TLS mode needs, and allow Cloudflare's IP ranges so proxied traffic is not dropped at the firewall.
What the symptom means
Cloudflare titles the fault "Error 521: web server is down" and states: "Error 521 occurs when the origin web server refuses connections from Cloudflare." Security solutions at the origin may block legitimate connections from certain Cloudflare IP addresses.
That differs from Error 520 (unexpected HTTP answer) and Error 522 (connect timeout). With 521, TCP is refused.
The two most common causes are: "Offlined origin web server application" and "Blocked Cloudflare requests."
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
| Origin web server application offline | 521 on every path; nothing listens on 80 or 443 | Host process list and listener check on the origin |
| Firewall or security software blocks Cloudflare IPs | 521 after a firewall or plugin change | Compare blocked sources with Cloudflare IP ranges |
| Wrong port for the SSL/TLS mode | 521 while HTTP works locally on another port | Match Flexible to port 80, or Full / Full (Strict) to port 443 |
| Full or Full (Strict) without HTTPS on the origin | 521 after SSL mode was raised | Confirm TLS listens on 443 and a certificate is installed |
AWS VPC route captures Cloudflare 172.64.0.0/13 |
521 from some Cloudflare locations only | Check VPC routes that cover 172.x.x.x to an internal target |
Prove the cause before changing anything
These steps only read.
-
Confirm the origin application is running and bound to the expected port. Review origin error logs for crashes or outages.
-
Check SSL/TLS > Overview. If mode is Full or Full (Strict), the origin must support HTTPS with a Cloudflare Origin Certificate or a certificate matching those modes, and must listen on "Port 80 for Flexible, or Port 443 for Full and Full (Strict)."
-
Confirm Cloudflare IP addresses are not blocked or rate limited. Proxied traffic reaches the origin from Cloudflare IP addresses, so blocking them prevents visitor traffic from reaching the application.
-
On AWS, a VPC route conflict with Cloudflare egress
172.64.0.0/13can cause 521 or 522 when a broad172.x.x.xroute points at an internal gateway instead of the Internet Gateway.
Fix
Allow Cloudflare IP ranges at the origin firewall
Replace $ip with each Cloudflare IPv4 or IPv6 range from Cloudflare's published list at https://www.cloudflare.com/ips/ (the list the Cloudflare IP addresses page links).
Save the current packet filter first:
iptables-save > /root/iptables-before-cloudflare-allow.rules
ip6tables-save > /root/ip6tables-before-cloudflare-allow.rules
Risk: the next commands insert ACCEPT rules for Cloudflare source ranges on ports http and https. Wrong ranges leave 521 in place; overly broad ranges accept more sources than you intended on those ports.
For each Cloudflare IPv4 range:
iptables -I INPUT -p tcp -m multiport --dports http,https -s $ip -j ACCEPT
For each Cloudflare IPv6 range:
ip6tables -I INPUT -p tcp -m multiport --dports http,https -s $ip -j ACCEPT
To undo it: restore the saved rulesets only if you have made no other firewall change since saving (restore replaces the whole rule set):
iptables-restore < /root/iptables-before-cloudflare-allow.rules
ip6tables-restore < /root/ip6tables-before-cloudflare-allow.rules
The Cloudflare IP addresses page also says to check that any security plugins — such as those for WordPress — allow Cloudflare IP addresses, and that the ModSecurity plugin is up to date. Checking host firewall panels and security groups the same way is this article's own advice. The executable allow steps above are the iptables shape for the host firewall.
Match SSL/TLS mode to the origin listener
The Error 521 page says to make sure the origin listens on the port the SSL/TLS mode needs (port 80 for Flexible, or port 443 for Full and Full (Strict)). Matching the zone's mode to what the origin already serves is this article's own advice; the page does not tell you to change the mode. Full uses HTTPS to the origin for HTTPS visitors without validating the origin certificate; Full (strict) adds validation.
If you do change the mode, record the current encryption mode from SSL/TLS > Overview first. Write the mode the Overview tab shows:
echo "ssl_mode=<mode shown in Overview>" > cloudflare-ssl-mode-before.txt
Risk: the next step changes how Cloudflare connects to the origin for the zone. Moving from Flexible to Full or Full (strict) switches HTTPS visitor fetches to HTTPS on the origin, so a missing listener or certificate on port 443 keeps returning 521.
In SSL/TLS > Overview, set the mode to match what the origin serves: Full or Full (strict) only when port 443 answers TLS; Flexible when the origin serves HTTP on port 80.
To undo it: set the encryption mode back to the value in cloudflare-ssl-mode-before.txt.
Example (illustrative): after a firewall rebuild, nginx still listens on 443 under Full (strict) but iptables has no Cloudflare ACCEPT lines. Re-adding the published ranges restores proxied access.
Confirm the fix
- Reload the proxied hostname; it should not return Error 521.
- Confirm the origin listens on port 80 (Flexible) or 443 (Full / Full (Strict)).
- Confirm origin firewall logs accept Cloudflare sources again.
What to watch afterwards
- Firewall or plugin updates that drop Cloudflare allow rules.
- SSL/TLS mode changes before peak traffic.
- AWS VPC routes that capture
172.x.x.xafter Transit Gateway work.
Read next
Related articles you may want next.
- TroubleshootingCloudflare Error 520: Web server is returning an unknown errorCloudflare Error 520: origin returned an empty or unexpected response. Check crashes, Cloudflare IP blocks, headers over 128 KB and HTTP/2 to Origin.Read article
- TroubleshootingCloudflare Error 522: Connection timed outCloudflare Error 522: no SYN+ACK in 19s or no data above TCP in 90s. Allow Cloudflare IPs, check origin load, and verify the proxied DNS target.Read article
- Troubleshootingnginx 502 Bad Gateway: connect() failed (111: Connection refused) while connecting to upstreamnginx 502 Bad Gateway with connect() failed (111: Connection refused) while connecting to upstream. Match the error log line to the cause and fix it.Read article
Risks and limits
These steps have not been lab-tested.
Allowing Cloudflare ranges does not by itself block direct-to-origin traffic; dropping non-Cloudflare sources is a separate hardening step. Error 521 is not a bad HTTP body (that is Error 520). Error 521 does not use the 19-second or 90-second timers from Error 522.
Sources
- Error 521 — Cloudflare, Last updated Apr 23, 2026, accessed 1 December 2026
- Cloudflare IP addresses — Cloudflare, Last updated Apr 21, 2026, accessed 1 December 2026
- Encryption modes — Cloudflare, Last updated Apr 16, 2026, accessed 1 December 2026
This article was originally published on .