failover.io
  1. Home
  2. Cloudflare errors
  3. Error 521

Cloudflare error 521: your web server refused the connection

HTTP 521 from Cloudflare. Origin refused the connection: what it means, whose fault it is and how to fix it.

Updated 19 November 20265 min read

Cloudflare returns a 521 when it tried to connect to your origin server and the connection was refused. Either the web server isn't running, or something on the origin, usually a firewall, is rejecting Cloudflare's IP addresses.

Quick answer. Check that your web server (nginx, Apache, LiteSpeed) is running, then check that your firewall allows every current Cloudflare IP range from cloudflare.com/ips on ports 80 and 443.

Is a 521 error my fault?

Where the problem isHow often
Your originYes
CloudflareNo
The visitorNo

A 521 is always an origin problem. Cloudflare reached out and your server, or a firewall in front of it, said no.

What "refused" means

A refused connection and a timed-out one are different failures. With a timeout (a 522), Cloudflare knocked and got silence. With a 521, it got an active rejection: a TCP reset, or nothing listening on the port.

That narrows things down. Silence usually means an overloaded server or a firewall that drops packets, while a rejection means the process that should listen on the port isn't there, or a firewall is set to reject rather than drop.

Common causes, most likely first

  1. The web server is stopped or crashed. nginx, Apache or LiteSpeed died, was stopped for maintenance and never started again or didn't come back after a reboot. Check with systemctl status nginx (or apache2); if it's dead, start it and read the journal to see why it stopped.
  2. A firewall rejects Cloudflare's IP addresses. Because Cloudflare proxies all traffic, every request to your origin comes from a Cloudflare IP, so a rule in UFW, iptables, CSF, a hosting panel or a security plugin that blocks those ranges takes the whole site down. Allow the current ranges from cloudflare.com/ips.
  3. The web server runs but doesn't listen where Cloudflare connects, for example on the wrong port or interface. Check with ss -tlnp | grep -E ':80|:443'.
  4. The whole server is offline: a crashed VM, a host outage or a reboot in progress. If you can't reach it over SSH either, the fix is with your host.

How to fix error 521

  1. Log in to the origin over SSH, or through your host's console if SSH is down too. If you can't reach the server at all, it's a hosting problem.
  2. Check the web server with systemctl status nginx or systemctl status apache2, start it if it's stopped and look at the logs for the reason it stopped.
  3. Confirm it listens on 443: ss -tlnp | grep ':443'.
  4. Check the firewall rules for Cloudflare's ranges. With UFW, ufw status numbered lists them. Cloudflare's IPs must be allowed on 80 and 443.
  5. Test from another machine, bypassing Cloudflare: curl -v --connect-timeout 10 --resolve yourdomain.com:443:ORIGIN_IP https://yourdomain.com/. "Connection refused" confirms the rejection.

Why the Cloudflare IP allowlist matters

With the orange cloud on, your origin IP is hidden and every real visitor reaches your server through a Cloudflare IP. A firewall that only allows known traffic and doesn't know Cloudflare's ranges rejects every visitor. Cloudflare publishes its ranges at cloudflare.com/ips and changes them from time to time, so update the allowlist with a script rather than typing it in once.

Know the minute your origin stops answering

A stopped web server stays stopped until someone notices. An HTTP monitor on the site fails on the 521 and starts your alert chain; failover.io checks the failure again from a second location first, so a network problem on our side doesn't wake you.

All six codes side by side: Cloudflare 5xx errors explained.

Frequently asked questions

What does Cloudflare error 521 mean?

Your origin refused Cloudflare's connection. The web server is stopped, the server is offline or a firewall rejects Cloudflare's IP addresses.

How do I fix Cloudflare error 521?

Check that nginx or Apache runs with systemctl status, that it listens on port 443 and that your firewall allows every Cloudflare range from cloudflare.com/ips on ports 80 and 443. If you can't reach the server at all, contact your host.

What is the difference between error 521 and 522?

A 521 is a refusal: a reset or a closed port. A 522 is silence: no answer in time. A refusal points to a stopped process or a rejecting firewall; silence points to overload or a firewall that drops packets.