How HTTP Works
5xx · Server errorNon-standard · Cloudflare
< HTTP/1.1 521 Web Server Is Down

521 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.

Reviewed 2 min readintermediate2 sourcesTry itMarkdown
Cacheable
No
Retry?
Yes, once the origin is back up
Usually sent by
Cloudflare edge
Spec
Cloudflare error 521
Often confused with
522, 523
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

  1. Is the origin up and listening?

    systemctl status nginx
    ss -tlnp | grep -E ':(80|443)\b'
  2. 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 443

    Connection refused confirms the problem. If it works from your laptop but not via Cloudflare, the firewall is selectively blocking Cloudflare.

  3. Allowlist Cloudflare’s published ranges (https://www.cloudflare.com/ips-v4 and ips-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
  4. 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 (nginx ngx_http_realip_module) so your tools see real client IPs.

  5. 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.

  6. Server overload. An exhausted backlog or max_connections can refuse new connections; check ss -s, netstat -s | grep -i listen, and increase listen ... backlog and worker limits.

  7. 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

CodeCause
521Connection actively refused
522Connection attempt timed out (packets dropped)
523No route to the origin IP
520Connected, but the response was empty, reset or malformed

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

  1. Cloudflare: 521 Errordevelopers.cloudflare.com
  2. Cloudflare HTTP Status Codesdevelopers.cloudflare.com

Keep going

Browse /search