Introduction
Cloudflare 520 errors occur when the origin web server returns an empty, unknown, or unexpected response to Cloudflare's request. The connection succeeds, but the server's response is unparseable or missing.
Symptoms
Browser error:
``` 520 Web Server Returned an Unknown Error
Error 520 is a generic message that means the origin server returned something unexpected to Cloudflare. ```
Cloudflare dashboard:
{
"error": "520",
"description": "Web server returned an unknown error",
"client_ip": "1.2.3.4",
"ray_id": "abc123def456"
}curl test:
```bash $ curl -I https://example.com
HTTP/2 520 date: Mon, 15 Apr 2024 10:00:00 GMT content-type: text/html; charset=UTF-8 x-frame-options: SAMEORIGIN cf-ray: abc123def456-LAX ```
Common Causes
- 1.Empty response - Server closes connection without sending data
- 2.Malformed headers - Invalid HTTP header format
- 3.Server crash - Application crashes mid-response
- 4.Connection reset - Server terminates connection abruptly
- 5.Firewall blocking - Server firewall dropping Cloudflare IPs
- 6.Protocol mismatch - HTTP/HTTPS or HTTP version mismatch
- 7.Large response headers - Headers exceed buffer size
Step-by-Step Fix
Step 1: Test Direct Origin Access
```bash # Test origin server directly (bypass Cloudflare) curl -I http://YOUR_ORIGIN_IP
# Test with Host header curl -I -H "Host: example.com" http://YOUR_ORIGIN_IP
# Test HTTPS if origin uses SSL curl -I -k https://YOUR_ORIGIN_IP
# If direct access works, issue is Cloudflare-specific # If direct access also fails, origin has issues ```
Step 2: Check Origin Server Logs
```bash # Check Apache error logs tail -f /var/log/apache2/error.log
# Check Nginx error logs tail -f /var/log/nginx/error.log
# Check application logs tail -f /var/log/php-fpm/error.log tail -f /var/log/nodejs/app.log
# Look for: # - Segmentation faults # - Memory errors # - Connection resets # - Protocol errors ```
Step 3: Verify Origin Server Response
```bash # Check if server returns valid HTTP response curl -v http://YOUR_ORIGIN_IP 2>&1 | head -20
# Should see: # HTTP/1.1 200 OK # Content-Type: text/html
# Check response headers for issues curl -I -D - http://YOUR_ORIGIN_IP
# Check for malformed headers # Headers with invalid characters or too long ```
Step 4: Check Firewall Rules
```bash # Ensure Cloudflare IPs are allowed # List Cloudflare IP ranges curl https://www.cloudflare.com/ips-v4
# Check iptables (Linux) iptables -L -n | grep DROP
# Allow Cloudflare IPs for ip in $(curl -s https://www.cloudflare.com/ips-v4); do iptables -I INPUT -s $ip -p tcp --dport 80 -j ACCEPT iptables -I INPUT -s $ip -p tcp --dport 443 -j ACCEPT done
# Check UFW ufw status ufw allow from 173.245.48.0/20 to any port 80,443 ```
Step 5: Check Server Configuration
```nginx # Nginx: Check for buffer issues # /etc/nginx/nginx.conf http { client_body_buffer_size 128k; client_header_buffer_size 1k; large_client_header_buffers 4 16k; }
# Restart Nginx nginx -t && systemctl restart nginx ```
```bash # Apache: Check for timeout and buffer settings # /etc/apache2/apache2.conf Timeout 60 KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 5
# Restart Apache apachectl configtest && systemctl restart apache2 ```
Step 6: Check Application Health
```bash # Check if application is running systemctl status php-fpm systemctl status nodejs systemctl status gunicorn
# Check for memory issues free -m ps aux --sort=-%mem | head -10
# Check for segfaults in logs grep -i "segfault|segmentation fault" /var/log/syslog
# Restart application if crashed systemctl restart php-fpm ```
Step 7: Enable Cloudflare DNS Only Mode
```bash # Temporarily disable Cloudflare proxy # Cloudflare Dashboard > DNS > Toggle "Proxied" to "DNS only"
# Test if issue is Cloudflare-related curl -I https://example.com
# If works in DNS only mode: # - Check Cloudflare SSL/TLS settings # - Check page rules # - Check firewall rules
# Re-enable proxy after testing ```
Step 8: Check SSL/TLS Configuration
```bash # Cloudflare SSL/TLS settings: # - Off: No encryption between Cloudflare and origin # - Flexible: HTTPS to Cloudflare, HTTP to origin # - Full: HTTPS everywhere (origin cert not validated) # - Full (strict): HTTPS with valid origin certificate
# If using Full/Full (strict), verify origin certificate openssl s_client -connect YOUR_ORIGIN_IP:443 -servername example.com
# Certificate must be valid and not expired # For Full (strict), must be CA-signed or Cloudflare Origin CA ```
Step 9: Check Response Header Size
```bash # Large headers can cause 520 errors # Check header size curl -I http://YOUR_ORIGIN_IP | wc -c
# Nginx: Increase header buffer large_client_header_buffers 4 32k;
# Apache: Increase LimitRequestFieldSize LimitRequestFieldSize 32768 LimitRequestLine 32768 ```
Step 10: Contact Cloudflare Support
```bash # If issue persists: # 1. Enable Cloudflare support in dashboard # 2. Provide Ray ID from error page # 3. Share origin server details # 4. Include test results from direct access
# Get Ray ID from error page or logs # Ray ID format: abc123def456-LAX ```
Common 520 Causes and Fixes
| Cause | Symptom | Solution |
|---|---|---|
| Firewall blocking | Works from some IPs | Allow Cloudflare IPs |
| Server crash | Empty response | Fix application crash |
| Malformed headers | Invalid HTTP | Fix server config |
| Memory limit | OOM errors | Increase memory |
| SSL mismatch | Protocol error | Fix SSL settings |
Verification
```bash # After fixing origin issues # Test direct access curl -I http://YOUR_ORIGIN_IP
# Should return valid HTTP response
# Re-enable Cloudflare proxy # Test via Cloudflare curl -I https://example.com
# Should return 200 OK instead of 520
# Monitor for 520 errors # Cloudflare Dashboard > Analytics > Errors ```
Prevention
To prevent Cloudflare 520 web server errors from recurring, implement these proactive measures:
1. Monitor Origin Server Health
groups:
- name: cloudflare-origin
rules:
- alert: Cloudflare520Errors
expr: |
rate(cloudflare_520_errors_total[5m]) > 0
for: 2m
labels:
severity: critical
annotations:
summary: "Cloudflare 520 errors detected"2. Configure Health Checks
```bash # Set up origin health monitoring # Create monitoring script cat << 'EOF' > /usr/local/bin/health_check.sh #!/bin/bash ORIGIN_IP="10.0.0.1"
# Test HTTP response HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://$ORIGIN_IP)
if [ "$HTTP_CODE" != "200" ]; then echo "Origin returned $HTTP_CODE" # Alert or restart service systemctl restart nginx fi EOF
chmod +x /usr/local/bin/health_check.sh echo "*/1 * * * * root /usr/local/bin/health_check.sh" > /etc/cron.d/origin-health ```
3. Configure Proper Error Handling
```nginx # nginx.conf - Handle errors gracefully server { listen 80; server_name example.com;
location / { proxy_pass http://backend; proxy_intercept_errors on; error_page 500 502 503 504 /error.html; }
location = /error.html { root /var/www/html; internal; } } ```
Best Practices Checklist
- [ ] Monitor origin server health
- [ ] Configure health checks
- [ ] Handle errors gracefully
- [ ] Monitor server resources
- [ ] Use Cloudflare monitoring
- [ ] Document origin IP changes
Related Issues
- [Fix Cloudflare 521 Web Server Is Down](/articles/fix-cloudflare-521-web-server-down)
- [Fix Cloudflare 522 Connection Timed Out](/articles/fix-cloudflare-522-connection-timed-out)
- [Fix Cloudflare 524 A Timeout Occurred](/articles/fix-cloudflare-524-a-timeout-occurred)
Related Articles
- [Cloudflare CDN troubleshooting: Fix Cloudflare Always Online Stale Html Broken Lin](cloudflare-always-online-stale-html-broken-links)
- [Cloudflare CDN troubleshooting: Cloudflare Cache Everything Rule Breaks WooCommerc](cloudflare-cache-everything-breaking-woocommerce-cart-cookies)
- [Cloudflare CDN troubleshooting: Fix Cloudflare Cache Purge Not Propagating All Edg](cloudflare-cache-purge-not-propagating-all-edge-locations)
- [Cloudflare CDN troubleshooting: Fix Cloudflare DNS Proxy Orange Cloud Blocking Ssh](cloudflare-dns-proxy-orange-cloud-blocking-ssh)
- [Cloudflare CDN troubleshooting: Fix Cloudflare Error 520 Web Server Returns Empty ](cloudflare-error-520-web-server-returns-empty-response)
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Fix Cloudflare 520 Web Server Returned an Unknown Error", "description": "Troubleshoot Cloudflare 520 errors. Fix origin server empty responses, malformed HTTP, and connectivity issues.", "url": "https://www.fixwikihub.com/fix-cloudflare-520-web-server-returned-unknown-error", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2026-04-03T15:39:40.179Z", "dateModified": "2026-04-03T15:39:40.179Z" } </script>