HTTP 521 · 5XX Cloudflare Edge Cacheable: No Retryable: Yes (after origin recovery)

HTTP 521 Web Server Is Down: Root Causes & Production Fix Guide

Cloudflare Error 521 means your origin server actively refused Cloudflare's TCP connection (`ECONNREFUSED`). Either Nginx/Apache/Caddy is stopped, not listening on port 443, or a firewall is actively rejecting Cloudflare IPs.

Top Root Causes of HTTP 521

Verify Origin Port 443 & Allowlist Cloudflare IPs

# Check listening sockets on origin
ss -tlnp | grep -E ':80|:443'

# Verify Nginx is active and config is valid
sudo nginx -t && sudo systemctl restart nginx

# Ensure UFW allows HTTPS (or restrict specifically to Cloudflare IP ranges)
sudo ufw allow 443/tcp

Verify with cURL

curl -i -sS --connect-timeout 5 https://ORIGIN_IP -H 'Host: example.com' -k

Interactive Stack Diagnoser (HTTP 521)

Frequently Asked Questions

What is the difference between Cloudflare 521 and 522?

521 means the origin actively refused the connection immediately (RST/port closed/firewall reject). 522 means packets were silently dropped and the TCP handshake timed out.

Why did I get 521 right after switching SSL to Full (Strict)?

Full (Strict) requires your origin to listen on port 443 with a valid SSL certificate (such as a free Cloudflare Origin Certificate or Let's Encrypt cert).

Can fail2ban cause 521 errors?

Yes! If fail2ban sees Cloudflare's edge IPs instead of real visitor IPs, it can ban Cloudflare itself. Configure `real_ip_header CF-Connecting-IP` and whitelist Cloudflare IPs.

Related Status Guides & Header Tools