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.
Error 520 usually originates from the origin server, not from Cloudflare. Here are the most common causes.
To resolve a 520, you need to identify whether the problem comes from your application, web server, or network configuration.
Resolution depends on the identified cause. Here are the most common fixes.
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.
Here are best practices to minimize occurrences of this error.
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.
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.
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.
Yes, MoniTao detects all 5xx codes, including Cloudflare-specific codes (520-527). You'll receive an alert as soon as the error is detected.
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.
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.
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.
Start free, no credit card required.