What Error 521 Means
With a proxied site, the edge opens a TCP connection to your origin on port 80 or 443. Error 521 means the origin answered that attempt with a refusal. The server is online, but nothing accepted the connection. If the attempt gets no answer at all, the edge shows error 522 instead; the same refusal without a CDN appears in the browser as ERR_CONNECTION_REFUSED.
If You See It on Someone Else's Site
- Wait and reload: the CDN is working; the site's own web server is not accepting connections.
- Nothing on your side helps: another browser or a cleared cache gives the same page.
- Tell the site owner the time and the Ray ID shown on the page.
Is the Web Server Running?
systemctl status nginx
sudo journalctl -u nginx -n 50 --no-pager
For Apache, use apache2 on Debian and Ubuntu or httpd on AlmaLinux and Rocky Linux. If the service is stopped or failed, the journal shows the reason: a configuration error after an edit, a missing certificate file, or a port held by another program. Test, then start:
sudo nginx -t
sudo systemctl start nginx
If it stopped because the server ran out of memory, sudo journalctl -k | grep -i oom shows it.
Are Ports 80 and 443 Open?
sudo ss -ltnp | grep -E ':80 |:443 '
Which port matters depends on the SSL mode. In Flexible mode the edge connects on port 80. In Full and Full (strict) it connects on 443 for HTTPS visitors, so a server without an HTTPS server block refuses those requests. If you see 127.0.0.1 instead of 0.0.0.0, the web server accepts local connections only; correct its listen lines.
Firewall Rules for the CDN Ranges
sudo ufw status numbered # Ubuntu and Debian
sudo firewall-cmd --list-all # AlmaLinux and Rocky Linux
A rule that rejects traffic produces a refusal, so a 521 points to a reject rule rather than a silent drop. If you allow web traffic only from the CDN, the list of ranges must be complete and current: Cloudflare publishes them, and error 522 shows how to load them into ufw and firewalld. Keep your SSH rule in place while you change rules, test from a second SSH session before you close the first, and check any firewall in your provider's control panel too.
Fail2ban Bans on Edge Addresses
Behind the CDN, every request arrives from an edge address. A Fail2ban jail that counts failed logins or errors by connecting address then bans edge servers, and every visitor routed through them gets a 521. Check and lift bans:
sudo fail2ban-client status
sudo fail2ban-client status JAIL
sudo fail2ban-client set JAIL unbanip EDGE_IP
Replace JAIL with the jail name and EDGE_IP with the banned address. To stop it happening again, add the CDN ranges to ignoreip in /etc/fail2ban/jail.local, and make Nginx log the real visitor address with set_real_ip_from and real_ip_header CF-Connecting-IP.
A Wrong Origin Address
The proxied A record must hold your server's current IP. If it points to an old server that is still online but runs no web server, every request is refused. Compare the record in the Cloudflare DNS settings with ip -4 addr show on the server.
Test the Origin Directly
curl -I --resolve example.com:443:203.0.113.10 https://example.com/
A status line means the origin accepts connections from that machine. A "Connection refused" error reproduces the 521. Run the test from a machine that your firewall treats like the edge, or temporarily from one you allow.
Confirm the Fix
curl -I https://example.com/
Expect 200 and a cf-ray header. If the edge now reports a handshake failure on port 443, see error 525.