Skip to content

Troubleshooting guide

Cloudflare error 521: web server is down

A 521 means your server actively refused Cloudflare's connection. Either nothing is listening on the port, or something on the server is turning Cloudflare away.

5 min read10 sectionsUpdated

On this page

Key points

  • 521 = connection refused by the origin.
  • Check the web server first: is it running and listening on 80 and 443?
  • Then the firewall: rate limiting or security tools that block Cloudflare's IP ranges cause 521 for everyone.
  • Check the DNS record in Cloudflare points at the right server.

What error 521 means

Cloudflare tried to open a TCP connection to your origin on port 80 or 443 and the server answered with a refusal (a TCP reset). That is different from a timeout (522), where the server never answers at all.

ErrorWhat Cloudflare sawWhere to look first
520A connection, then an empty, invalid or reset responseOrigin application and web server error logs
521The origin actively refused the TCP connectionIs the web server running; does the firewall allow Cloudflare
522No TCP connection within Cloudflare's time limitServer load, firewall dropping packets, wrong DNS record
524A connection, but no HTTP response within 100 secondsSlow requests: long queries, reports, exports, uploads

The usual causes

  • The web server is stopped or crashed: nginx, Apache, Caddy or your application server is not running, or failed after a configuration change.
  • It listens on the wrong port or address, for example only on 127.0.0.1, or on 8080 while Cloudflare connects to 443.
  • A firewall blocks Cloudflare. Hosting firewalls, iptables rules, fail2ban or a security plugin may block Cloudflare's addresses, often after seeing many requests from them (all your visitors arrive through them).
  • SSL mode mismatch. With an SSL mode that connects to the origin over HTTPS, an origin that does not listen on 443 refuses the connection.
  • The DNS record points at an old server that no longer runs the site.

Confirm it

bash
# on the server: is anything listening on 80 and 443?
sudo ss -ltnp | grep -E ':(80|443) '
# is the web server running?
sudo systemctl status nginx
# from outside, bypassing Cloudflare
curl -sv --resolve example.com:443:203.0.113.10 https://example.com/ -o /dev/null
# firewall rules that drop or reject
sudo iptables -S | head -50

Fix it

  1. Start or fix the web server, and run its config test (nginx -t) before reloading, so a typo does not take it down again.
  2. Listen on the right address and ports: 0.0.0.0:443 (or the public interface), and port 80 if Cloudflare connects over HTTP.
  3. Allow all of Cloudflare's IP ranges in every firewall on the path, and exclude them from rate limiting and ban tools; Cloudflare publishes the list on its website.
  4. Match the SSL mode to what the origin supports: if the origin serves HTTPS, use a mode that connects over HTTPS with a valid certificate on the origin.
  5. Check the DNS record in the Cloudflare dashboard against the server's current IP address.

Catch it before your visitors do

Cloudflare's error pages hide the cause, so measure both sides:

  1. Check the public URL through Cloudflare with an uptime monitor from several regions. That is what visitors get, 52x errors included.
  2. Check the origin directly with a second monitor on the origin's address or a health endpoint that bypasses Cloudflare. If only the first one fails, the problem is between Cloudflare and your server; if both fail, it is the server.
  3. Alert on the status code, not only on "down". A rule for any 52x response on the public check tells you which of the four errors it is before anyone opens a log.
  4. Keep the CF-Ray ID. It is in the error page and in the cf-ray response header; Cloudflare support and your own logs can be matched with it.

With APM on the origin you can also see the request that took 100 seconds behind a 524, instead of guessing.

Frequently asked questions

How is 521 different from 522?

521 means the origin refused the connection, usually because nothing is listening or a firewall rejects it. 522 means the connection attempt timed out, usually because the server is overloaded or packets are dropped silently.

My site works when I visit the IP address directly. Why 521?

Your own IP is probably allowed while Cloudflare's ranges are blocked or rate limited. Check firewall, security plugin and fail2ban rules for Cloudflare's addresses.

Does 521 affect SEO?

Short outages rarely do. If crawlers keep getting 5xx errors for days, pages can drop from the index, which is why alerting on 521 within minutes matters.

Check it now, free

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.