Troubleshooting Cloudflare’s Mysterious Error 520: A Step-by-Step Guide
You’ve undoubtedly encountered it: a visitor clicks on your website link with anticipation, expecting relevant content, services, or solutions. Instead, they’re greeted with a stark message: “Error 520: Web server is returning an unknown error.” No helpful details, no clear guidance on what to do next, just pure confusion.
This error is Cloudflare’s way of saying, “I tried to connect to your server, but something went wrong, and I’m not sure exactly what.” Unlike more specific HTTP errors like 404 (Not Found), 500 (Internal Server Error), or 503 (Service Unavailable), 520 is a catch-all error code that requires investigation to resolve.
The consequences can be significant. Every minute that a 520 error persists translates to lost revenue, damaged trust, and potential SEO penalties. Google notices when your website experiences errors, and prolonged issues can negatively impact search rankings. For e-commerce sites, a 520 error during the checkout process can instantly drive conversion rates to zero.
This guide provides a systematic approach to help you differentiate between a quick fix and a prolonged outage. By following these steps, you should be able to resolve most 520 errors within 15 minutes – or at least clearly identify the kind of professional help you need.

Understanding the Real Meaning of Error 520
Error 520 arises when Cloudflare, acting as an intermediary between visitors and your origin server, receives an unexpected response (or no response at all) from your server. Think of it as a failed phone call: the other party answers but doesn’t speak, or speaks in a language the phone can’t understand.
Specifically, the error indicates that:
- The origin server has crashed or is unresponsive.
- The server returned an empty response.
- The request headers exceeded Cloudflare’s 16 KB limit (or a total of 32 KB, with 16 KB per header).
- The server sent malformed or non-HTTP compliant data.
- The TCP connection timed out or was unexpectedly reset.
It’s crucial to understand that 520 is a server-side error. While Cloudflare displays the error message, the root cause lies with your origin server. This means resolving the issue requires accessing your server or coordinating with your hosting provider.
Phase 1: Immediate Diagnosis (5 Minutes)
Step 1: Completely Bypass Cloudflare
Before diving into server logs, confirm that the problem lies between Cloudflare and your server, rather than the server itself.
Option A: Pause Cloudflare
- Log in to the Cloudflare console → Select your domain.
- Go to “Overview” → “Advanced Actions.”
- Click “Pause Cloudflare on Site” → Confirm.
Option B: Development Mode
If you can’t fully pause (perhaps due to security concerns), enable Development Mode:
- Go to “Caching” → “Configuration.”
- Toggle Development Mode to “On.”
- This bypasses caching while keeping security features enabled.
Direct Testing: Access your website using your server’s IP address (if known) or after pausing Cloudflare services. If the website loads normally, the 520 error stems from communication issues between Cloudflare and your server. If it still fails to load, your origin server has an independent problem.
Step 2: Check Server Status
Having bypassed Cloudflare, verify that your origin server is indeed running correctly:
# Test server responsiveness
curl -I http://your-server-ip/
# Check if specific pages work
curl -v http://your-server-ip/important-page
# For HTTPS sites
curl -vk https://your-server-ip/
Check for an HTTP 200 response. If you receive “Connection refused,” timeouts, or 5xx errors, troubleshoot your server immediately before dealing with the Cloudflare integration.
Phase 2: Root Cause Analysis (10 Minutes)
Common Cause 1: Server Crash or Resource Exhaustion
Symptoms: Website runs briefly after a restart, then fails. High traffic correlates with error occurrence.
Diagnosis:
# Check server resources
free -h # Memory usage
df -h # Disk space
uptime # Load average
top # Process resource consumption
Fixes:
- Restart the web server:
sudo systemctl restart apache2orsudo systemctl restart nginx - Restart PHP-FPM if necessary:
sudo systemctl restart php8.1-fpm - Scale resources: Upgrade CPU/memory or implement load balancing.
- Check for runaway processes:
ps aux --sort=-%mem | head -20
Common Cause 2: Firewall Blocking Cloudflare’s IP Addresses
Symptoms: 520 errors appear suddenly after a firewall update. May be accompanied by other errors (521, 522).
Cloudflare publishes its IP address ranges at cloudflare.com/ips. Your server must accept connections from these ranges.
Diagnosis:
Check firewall logs for dropped connections from Cloudflare IPs:
# Check iptables
sudo iptables -L -n | grep DROP
# Check UFW status
sudo ufw status verbose
# Check fail2ban (often culprit)
sudo fail2ban-client status
sudo fail2ban-client status apache-auth
Fixes:
For UFW:
# Allow all Cloudflare IPs (IPv4)
sudo ufw allow from 173.245.48.0/20
sudo ufw allow from 103.21.244.0/22
sudo ufw allow from 103.22.200.0/22
sudo ufw allow from 103.31.4.0/22
sudo ufw allow from 141.101.64.0/18
sudo ufw allow from 108.162.192.0/18
sudo ufw allow from 190.93.240.0/20
sudo ufw allow from 188.114.96.0/20
sudo ufw allow from 197.234.240.0/22
sudo ufw allow from 198.41.128.0/17
sudo ufw allow from 162.158.0.0/15
sudo ufw allow from 104.16.0.0/12
sudo ufw allow from 172.64.0.0/13
sudo ufw allow from 131.0.72.0/22
sudo ufw reload
For Apache (.htaccess):
Require ip 173.245.48.0/20
Require ip 103.21.244.0/22
# ... all Cloudflare ranges
Common Cause 3: Excessive Header Size or Cookie Issues
Symptoms: 520 errors occur for logged-in users, but not anonymous visitors. The error is related to feature-rich applications (WordPress with many plugins installed).
Cloudflare enforces strict header limits: 32 KB total, 16 KB per header. Excessive cookies, oversized authentication tokens, or lengthy debugging headers can trigger this limit.
Diagnosis:
Generate a HAR (HTTP Archive) file to inspect request headers:
Chrome:
- Right-click → Inspect → “Network” tab.
- Ensure the red record button is active.
- Check “Preserve log.”
- Reproduce the 520 error.
- Right-click on a network entry → “Save all as HAR with content.”
Analyze the HAR file using Google’s HAR Analyzer or manually inspect for:
- Cookie size (each should be less than 4 KB).
- Duplicate cookies.
- Overly long custom headers.
- Accidentally leaving debugging headers in production.
Fixes:
- Clear browser cookies for your domain.
- Reduce cookie usage by WordPress plugins.
- Enable cookieless domains for static resources.
- Remove unnecessary headers on the origin server.
Common Cause 4: TCP Timeout Mismatch
Symptoms: 520 errors occur during slow page loads, large file uploads, or complex database queries.
Cloudflare expects a response within a specific timeframe. If your server takes too long to respond, Cloudflare interprets it as a failed request.
Diagnosis:
Check server timeout settings:
# Apache KeepAlive
grep -i keepalive /etc/apache2/apache2.conf
# Nginx timeouts
grep -i timeout /etc/nginx/nginx.conf
# PHP max execution time
grep max_execution_time /etc/php/*/fpm/php.ini
Fixes:
Ensure TCP timeout exceeds 300 seconds (5 minutes):
# Nginx configuration
keepalive_timeout 300s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
Apache
# Apache configuration
KeepAlive On
KeepAliveTimeout 300
Common Cause 5: SSL/TLS Handshake Failures
Symptoms: 520 errors occur on HTTPS websites, especially after updating certificates or changing SSL modes in Cloudflare.
Diagnosis:
Independently test the SSL handshake:
openssl s_client -connect your-origin-ip:443 -servername yourdomain.com
Check for:
- Expired certificates.
- Certificate chain issues.
- Protocol mismatches (TLS 1.0/1.1 disabled but required).
- Incompatible cipher suites.
Fixes:
- Renew expired certificates.
- Ensure the certificate chain is complete (intermediate certificates).
- Adjust Cloudflare SSL modes to match origin capabilities:
- Flexible: HTTPS requests forwarded to Cloudflare, HTTP requests forwarded to origin (insecure, not recommended).
- Full: HTTPS connection to origin, accepts any certificate.
- Full (Strict): Requires HTTPS connection to origin with a valid certificate.
Phase 3: Verification and Prevention
Testing Your Fix
After implementing a fix:
- Re-enable Cloudflare: Switch DNS records back to “Proxied” (orange cloud icon).
- Purge the cache: Cloudflare console → Caching → Purge Everything.
- Test from multiple locations: Use a VPN or proxy service to verify global accessibility.
For comprehensive verification, test from different geographic locations. A residential proxy network supports real-world testing from over 190 countries, ensuring your fix works globally – not just in your location. Static residential proxies enable continuous monitoring of specific regions, while dynamic rotation verifies that firewall rules aren’t inadvertently blocking legitimate Cloudflare traffic from certain areas.
Prevention Strategies
| Strategy | Implementation | Frequency |
|---|---|---|
| Monitor Origin Health | Use Pingdom, UptimeRobot, or Datadog for availability monitoring | Continuous |
| Log Analysis | ELK stack or Splunk for error pattern detection | Real-time |
| Firewall Automation | Ansible/Puppet to maintain Cloudflare IP whitelist | On IP range updates |
| Header Audits | Automated HAR analysis in CI/CD pipeline | Each deployment |
| Capacity Planning | Load testing based on realistic traffic patterns | Quarterly |
When to Contact Support
If the 520 error persists after these steps, prepare the following information for Cloudflare support:
- The full URL where the error occurred.
- The Cloudflare Ray ID from the 520 error page.
- Output from
http://yourdomain.com/cdn-cgi/trace - Two HAR files: one with Cloudflare enabled, one without.
The 520 Resolution Framework
Error 520 is frustrating because it lacks specific information. But with a systematic diagnosis – bypassing Cloudflare, checking server status, auditing firewalls, analyzing request headers, and verifying SSL – the vast majority of cases can be resolved quickly.
Key Insight: 520 is a symptom, not the disease. The root cause always lies on the server-side, whether it’s a crash, configuration issue, or resource limitation. By addressing the root cause, Cloudflare’s “unknown error” becomes a known solution.

Troubleshooting Error 520 requires testing from multiple network perspectives to differentiate between regional issues and global outages. When you need to verify fixes across geographies or monitor website health from a global user’s perspective, a residential proxy network can provide the infrastructure you need. With residential IPs covering 190+ countries, you can test website accessibility as real users would, ensuring firewall rules are effective globally and that Cloudflare integrations succeed everywhere. Static residential proxies support continuous monitoring from specific regions, while millisecond-level response times and 99.9% uptime ensure your diagnostic tests run without delay. Don’t guess whether your 520 error fix works – leverage to perform comprehensive verification. Sign up today and integrate professional-grade testing infrastructure into your website reliability workflow.