< HTTP/1.1 521 Web Server Is Down521 Web Server Is Down
Cloudflare-specific status code indicating the origin server refused the connection. Learn about this proxy error and how to troubleshoot it.
- Cacheable
- No
- Retry?
- Yes, once the origin is back up
- Usually sent by
- Cloudflare edge
On this page
TL;DR: Cloudflare tried to open a TCP connection to your origin and was refused. Either nothing is listening on the port Cloudflare uses, or a firewall is rejecting Cloudflare’s IP ranges. Test the origin IP directly from outside your network.
What it means
521 is Cloudflare-specific: the connection was actively refused (RST or ICMP rejection), as opposed to 522, where packets vanish and the attempt times out. A refusal is fast, so a 521 appears immediately. The error page reads “Web server is down”.
Who sent it?
server: cloudflare and a cf-ray header on the response. Nothing about this reached your application, so your app logs will be empty for these requests; check the web server, the host firewall and the cloud security group instead.
Fix it
-
Is the origin up and listening?
systemctl status nginx ss -tlnp | grep -E ':(80|443)\b' -
Is it reachable from the internet on the right port? Cloudflare connects to port 443 for Full and Full (strict) SSL modes, and to port 80 for Flexible. Test from a machine outside your network:
curl -sv --resolve example.com:443:203.0.113.10 https://example.com/ -o /dev/null nc -vz 203.0.113.10 443Connection refusedconfirms the problem. If it works from your laptop but not via Cloudflare, the firewall is selectively blocking Cloudflare. -
Allowlist Cloudflare’s published ranges (
https://www.cloudflare.com/ips-v4andips-v6) in iptables/nftables,ufw, CSF, AWS security groups and NACLs. Fetch the lists programmatically instead of pasting them; they change.for ip in $(curl -s https://www.cloudflare.com/ips-v4); do ufw allow from "$ip" to any port 443 proto tcp done -
Fail2ban and rate limiters. Because all traffic comes from Cloudflare edge IPs, a ban on one edge address blocks many visitors. Use
CF-Connecting-IP(nginxngx_http_realip_module) so your tools see real client IPs. -
Wrong port or SSL mode. Using Flexible SSL while the origin only listens on 443 refuses port 80 connections; switch to Full (strict) and serve a valid certificate. Non-standard origin ports require a Cloudflare Origin Rule (port override), and only some ports are proxied for DNS-based setups.
-
Server overload. An exhausted backlog or
max_connectionscan refuse new connections; checkss -s,netstat -s | grep -i listen, and increaselisten ... backlogand worker limits. -
Restart after a crash. A stopped service shows up as 521 exactly like a firewall block. Add a process supervisor (systemd
Restart=on-failure).
Real client IP behind Cloudflare (nginx)
set_real_ip_from 173.245.48.0/20; # repeat for every range in ips-v4 and ips-v6
real_ip_header CF-Connecting-IP;
521 vs similar
| Code | Cause |
|---|---|
| 521 | Connection actively refused |
| 522 | Connection attempt timed out (packets dropped) |
| 523 | No route to the origin IP |
| 520 | Connected, but the response was empty, reset or malformed |
Related
Frequently asked questions
What does Cloudflare error 521 mean?
A 521 error means Cloudflare cannot connect to your origin server because it is down or refusing connections. The server is unreachable from Cloudflare.
How do I fix a 521 error?
Verify your origin server is running, check that your web server (nginx, Apache) is started, ensure firewall allows Cloudflare IPs, and verify the correct ports are open.
What causes 521 errors?
Common causes include origin server crashed or stopped, firewall blocking Cloudflare IPs, web server not listening on expected ports, or server overloaded and refusing connections.
How do I whitelist Cloudflare IPs?
Add Cloudflare IP ranges to your firewall allowlist. Cloudflare publishes their IP ranges at cloudflare.com/ips. Update your firewall rules to allow these IPs on ports 80 and 443.
Sources
Related
508 Loop Detected: Proxy and Redirect Loops
508 Loop Detected means the server found an infinite loop while processing a request. Learn the WebDAV origin, proxy loops, CDN-Loop and how to find the cycle.
511 Network Authentication Required: Captive Portals
511 is returned by a network gateway, such as hotel or airport Wi-Fi, that requires login before granting internet access. Learn how apps should handle it.
520 Web Server Returned an Unknown Error
Cloudflare-specific error when the origin server returns an unexpected response. Learn about 520 errors and how to troubleshoot them.
522 Connection Timed Out
Cloudflare-specific error when unable to establish a TCP connection to the origin server. Learn how to diagnose and fix 522 timeout errors.