Cloudflare Error 521: Web server is down

Cloudflare found your origin’s address, knocked on the door, and got a hard “no” — nothing accepted the TCP connection. The edge is fine; the origin refused.

What visitors see

Error 521
Web server is down
The web server is not returning a connection. As a result, the web page is not displaying.
Cloudflare Ray ID: …

Only people going through the orange-cloud proxy see this page. Direct hits to the origin IP (or grey-cloud DNS) skip Cloudflare’s branded error.

521 vs 522 vs 524 vs 502

CodeWhat Cloudflare managedTypical cause
521DNS ok; TCP to origin refusedOrigin process down, wrong port, firewall REJECT
522TCP to origin timed outFirewall DROP, wrong IP, host unreachable, security group
524TCP + TLS ok; HTTP response too slowApp hung / slow DB; same family as 504
502 / 520Got something unusable from originCrash mid-response, empty reply, protocol mismatch
503Origin (or CF) said unavailableOverload, maintenance, drained pool

Rule of thumb: 521 ≈ “Connection refused” at the CDN edge. 522 ≈ “Connection timed out”. Fix the layer the table points at — do not raise timeouts for a 521.

Frequent real causes

Diagnose from outside and on the origin

# From your laptop (bypasses Cloudflare if you use the origin IP + Host header,
# or temporarily grey-cloud the record):
curl -svo /dev/null --connect-timeout 5 http://ORIGIN_IP/ -H "Host: example.com"
curl -svo /dev/null --connect-timeout 5 https://ORIGIN_IP/ -H "Host: example.com" -k

# Expect "Connection refused" for a true 521-style failure:
nc -vz ORIGIN_IP 443
nc -vz ORIGIN_IP 80

# On the origin (provider console / SSH if still up):
sudo ss -ltnp | grep -E ':80|:443|:3000'
sudo systemctl status nginx caddy apache2 your-app --no-pager
sudo journalctl -u nginx -u your-app -n 80 --no-pager

If ss shows nothing on 80/443, start or fix the listener before touching Cloudflare settings. Same “nothing accepted the port” idea as localhost refused to connect and ssh Connection refused.

Fix checklist

  1. Confirm 521 vs 522 — refused → this page; silent timeout → 522.
  2. Start the origin — bring nginx/Caddy/app back; enable on boot; watch for crash loops and OOM.
  3. Match port and bind address — public proxy must listen on the interface Cloudflare hits (or a local reverse proxy that does).
  4. Open 80/443 for Cloudflare — allow CONNECT (not only your home IP). Prefer allowlisting Cloudflare IP ranges if you lock the origin down.
  5. Check DNS A/AAAA — Cloudflare → DNS: orange-cloud record must point at the live origin.
  6. Align SSL/TLS mode — Flexible = HTTP to origin; Full (strict) = HTTPS with a valid cert on origin (Cloudflare Origin CA is fine).
  7. After TCP works — next failures may be 5xx from the app, redirects (too many redirects), or cert issues (525/526).

Related

All Cloudflare error codes · Cloudflare Error 523 · Cloudflare Error 520 · Cloudflare Error 525 · Cloudflare Error 526 · Cloudflare Error 522 · Cloudflare Error 524 · 502 Bad Gateway · HTTP 503 · HTTP 504 · localhost refused to connect · ECONNREFUSED · ssh Connection refused · Anvil HTTP status · Wirebook: when sites get tired

Questions

What does Cloudflare Error 521 mean?

Cloudflare resolved your origin and tried to connect, but the origin refused the TCP connection — usually nothing listening on 80/443, or a firewall REJECT.

How is 521 different from 522?

521 is an active refusal (like Connection refused). 522 is a timeout (packets dropped or host unreachable) — see the 522 guide.

How is 521 different from 502?

502 means Cloudflare got a bad or empty HTTP response from an origin that accepted the connection. 521 never got a TCP accept.

My site works on the origin IP but 521 through Cloudflare — why?

DNS may point Cloudflare at a different IP, SSL mode may expect HTTPS on 443 while only HTTP listens, or a firewall allows you but not Cloudflare’s ranges.

Does restarting Cloudflare fix 521?

No. 521 is almost always an origin listener/firewall/DNS problem. Fix the server, then purge cache if you still see a stale edge page.

Can ufw cause 521?

Yes if it REJECTs 80/443. A DROP policy more often surfaces as Error 522.

What should I check first on the server?

ss -ltnp for :80/:443, systemctl status for the web unit, and that the Cloudflare DNS A/AAAA record matches this host.

Published .

Try it

Related guides

Newest guides