Fixing error 521 requires restoring communication between Cloudflare (or another CDN) and your origin web server. This error means your server is actively refusing connections, not that Cloudflare is down. Follow the steps below to isolate and resolve the issue efficiently.
Step 1: Check and Fix Firewall Settings (Most Common Cause)
Firewalls are the #1 cause of error 521. Many servers block Cloudflare IPs by default, mistaking them for suspicious traffic.
Whitelist Cloudflare IP Addresses
Cloudflare connects to your server using its own IP ranges. If these IPs are blocked, your server will refuse connections.
What to do:
- Log in to your server or hosting control panel
- Locate your firewall (CSF, UFW, iptables, or hosting security tool)
- Whitelist all official Cloudflare IP ranges
For CSF Firewall (cPanel servers):
- Go to CSF > Firewall Configuration
- Add Cloudflare IPs under Allow IP Addresses
- Save and restart CSF
For UFW (Ubuntu servers):
sudo ufw allow from CLOUDFLARE_IP_RANGE
sudo ufw reload
Remove Temporary or Auto-Blocked Rules
Security plugins and firewalls often block IPs automatically.
Check these tools carefully:
- CSF temporary blocks
- Fail2Ban
- Wordfence / iThemes Security
- Imunify360
Remove any Cloudflare IPs listed in:
- Temporary bans
- IP blocklists
- Rate-limiting rules
Step 2: Restart Your Web Server (Apache or NGINX)
A stalled or crashed web server can refuse new connections, triggering error 521.
Restart via Hosting Control Panel
If you use shared or managed hosting:
cPanel:
- Go to Service Status
- Restart Apache or Nginx
Plesk:
- Navigate to Tools & Settings > Services Management
- Restart the web server
Restart via SSH (VPS or Dedicated Server)
Log in via SSH and run:
For Apache:
sudo systemctl restart apache2
For NGINX:
sudo systemctl restart nginx
After restarting, refresh your website to see if the error is resolved.
Step 3: Verify Origin Server Is Online and Responding
If the server itself is down, Cloudflare cannot connect.
Run a Ping Test
From your local machine or terminal:
ping yourdomain.com
If there is no response, the server may be offline or blocked.
Check Server Resource Usage
High resource usage can cause your server to reject connections.
Check:
- CPU usage
- RAM consumption
- Disk space
- Active connections
In cPanel:
- Go to Resource Usage
- Look for limits being exceeded
On VPS:
top
df -h
free -m
If resources are maxed out, consider:
- Restarting services
- Upgrading hosting
- Reducing traffic spikes or bots
Step 4: Verify DNS Settings Are Correct
Incorrect DNS settings can cause Cloudflare to connect to the wrong server.
Check Your A Record
Make sure your domain’s A record points to the correct origin server IP.
Steps:
- Log in to Cloudflare DNS or your domain registrar
- Verify:
- Domain → Correct IP address
- No outdated or wrong IPs
Allow DNS Propagation
If you recently changed DNS:
- Wait up to a few hours
- Clear DNS cache
- Recheck connection status
DNS mismatches commonly trigger error 521 after server migrations.
Step 5: Temporarily Pause Cloudflare to Test
This helps confirm whether Cloudflare is part of the issue.
How to do it:
- Log in to Cloudflare
- Go to Overview
- Click Pause Cloudflare on the Site
If your website loads normally after pausing:
- The issue is between Cloudflare and your origin server
- Firewall or IP blocking is almost certainly the cause
Step 6: Check Web Server Logs for Exact Errors
Logs show exactly why connections are being refused.
Where to Look:
- Apache logs:
/var/log/apache2/error.log
- NGINX logs:
/var/log/nginx/error.log
Look for:
- connection refused
- blocked by a firewall
- too many connections
- permission denied
Logs provide the fastest path to the real root cause.
Step 7: Contact Your Hosting Provider
If all steps above fail, escalate with data.
Send your host:
- Error 521 screenshot
- Server logs
- Firewall rules checked
- Confirmation Cloudflare IPs are whitelisted
If the issue persists, reach out to your hosting provider for assistance. Provide logs and details of the steps you’ve already taken.
Leave a Reply