Cloudflare Error 520: Unknown Error

When your origin server returns an incomprehensible response

Error 520 is a Cloudflare-specific status code that doesn't exist in the standard HTTP specification. It indicates that the origin server returned an empty, malformed, or unexpected response that Cloudflare cannot interpret or forward to the client.

This error is particularly frustrating because it's often intermittent and difficult to reproduce. The response from the origin server is technically received, but its content is invalid. Unlike 521 (server unreachable) or 522 (connection timeout), 520 indicates a communication problem at the HTTP protocol level.

For sites behind Cloudflare, monitoring 520 errors is essential. MoniTao detects these errors in real-time and alerts you before your users complain. Understanding the causes allows you to put the right preventions in place.

Common causes of error 520

Error 520 usually originates from the origin server, not from Cloudflare. Here are the most common causes.

Diagnosing error 520

To resolve a 520, you need to identify whether the problem comes from your application, web server, or network configuration.

Solutions to fix error 520

Resolution depends on the identified cause. Here are the most common fixes.

Configuration to prevent 520 errors

Here are recommended configurations to avoid 520 errors:

# Nginx - /etc/nginx/nginx.conf
# Increase timeouts for Cloudflare
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;

# Keepalive with Cloudflare
keepalive_timeout 300;
keepalive_requests 10000;

# Larger headers if needed
large_client_header_buffers 4 16k;

# PHP - php.ini
memory_limit = 256M
max_execution_time = 30
output_buffering = 4096

# Error handling (never send empty response)
display_errors = Off
log_errors = On
error_log = /var/log/php-errors.log

These configurations ensure the server keeps connections open long enough for Cloudflare and that errors are logged rather than interrupting the response.

Preventing 520 errors

Here are best practices to minimize occurrences of this error.

520 diagnostic checklist

  • Direct test of origin server (bypass Cloudflare)
  • Web server error logs reviewed
  • PHP/application error logs checked
  • Server resources (CPU, RAM) monitored
  • Timeouts and keepalive correctly configured
  • Response headers validated with curl -I

Frequently asked questions

How do I test my site without going through Cloudflare?

Modify your machine's hosts file (C:\Windows\System32\drivers\etc\hosts or /etc/hosts) to point your domain directly to your origin server IP. You'll then see the real errors without Cloudflare intermediary.

Does error 520 come from Cloudflare or my server?

The 520 code is generated by Cloudflare, but the cause is almost always on your origin server. Cloudflare uses this code when it receives a response it cannot correctly interpret.

How do I use the Ray ID to diagnose?

The Ray ID appears on the error page. In the Cloudflare dashboard, go to Analytics > Traffic, filter by this Ray ID to see request details, sent and received headers.

Does MoniTao detect 520 errors?

Yes, MoniTao detects all 5xx codes, including Cloudflare-specific codes (520-527). You'll receive an alert as soon as the error is detected.

Why is error 520 intermittent?

Intermittent 520s are often related to load spikes that exhaust resources, race conditions in code, or keepalive issues. Monitor temporal patterns to identify the cause.

What's the difference between 520, 521, and 522?

520 indicates an invalid response, 521 that the server refuses connection (server down), and 522 that the connection timed out (network timeout). 520 is hardest to diagnose because the connection establishes but the response is incorrect.

Conclusion

Cloudflare error 520 is a signal that your origin server is returning invalid or truncated responses. While the code is generated by Cloudflare, the solution is almost always on your infrastructure: application errors, server configuration, or insufficient resources.

With MoniTao, detect 520 errors in real-time and act before your users are impacted. Proactive monitoring combined with good error handling and logging allows you to resolve these issues quickly.

Ready to Sleep Soundly?

Start free, no credit card required.