Learn how to fix Cloudflare Error 520 with 7 methods and discover the causes behind the web server returning an unknown error and how to prevent it in the future.
Cloudflare Error 520: Web Server Is Returning an Unknown Error
Website owners often encounter Error 520, an issue where Cloudflare fails to receive a valid response from the origin web server. This error is classified as an HTTP 5xx status code, meaning it stems from server-side issues rather than client-side problems. Unlike other server error codes, such as Error 502 (Bad Gateway) or Error 504 (Gateway Timeout), the 520 error is more generic, making it harder to diagnose.

The primary reason for this 520 unknown error is that the origin server either returns an invalid HTTP response or fails to respond at all. This can occur due to server overload, firewall misconfigurations, SSL certificate conflicts, corrupted .htaccess files, network connectivity issues, or incorrect DNS settings.
7 Ways to Fix Cloudflare Error 520
Here are the 7 most effective ways to fix the “Web Server Is Returning an Unknown Error.”
Verify Cloudflare DNS Settings
Incorrect DNS records in Cloudflare’s dashboard can prevent a proper connection between Cloudflare’s reverse proxy and the origin web server.
Log into Cloudflare, navigate to the DNS section, and ensure the A records and CNAME records match the correct origin server IP address. If an incorrect IP address is listed, Cloudflare will not be able to fetch website data, resulting in the 520 error.
If the domain is configured incorrectly, update the DNS records based on the settings provided by the hosting provider. Also, confirm that the proxy status is set correctly. If necessary, toggle Cloudflare’s proxy mode off by setting it to “DNS only” to test whether the issue is Cloudflare-related.
Check Server Response Headers and Cookies
Large or invalid HTTP response headers can lead to a 520 error. Cloudflare enforces a strict limit of 16 KB on response headers, including cookies and metadata. If the origin server sends excessive data, Cloudflare may reject the request.
Use Google Chrome Developer Tools (F12
> Network tab) to inspect the response headers. If they exceed 16 KB, reduce cookie sizes and optimize the headers. In some cases, modifying the web server configuration to limit header size can resolve the issue.
Review and Modify Firewall Rules
Overly strict firewall configurations can block Cloudflare’s IP addresses, preventing successful requests and triggering a 520 unknown error. Some security plugins and firewall services, such as Cloudflare’s WAF, ModSecurity, or Wordfence, may mistakenly block legitimate Cloudflare requests.
Check firewall logs in the hosting control panel or server configuration settings. If Cloudflare’s IPs appear in the blocked request logs, whitelist them in the firewall settings. A full list of Cloudflare’s IP ranges can be found on their official documentation.
If using a managed hosting provider, reach out to support and request that Cloudflare’s IP addresses be whitelisted.
Analyze Server Logs for HTTP 5xx Errors
Accessing server logs helps pinpoint the cause of Error 520. If the origin server is crashing, returning invalid responses, or encountering timeouts, the logs will provide clues.
For Apache servers, check error logs with the command:
tail -f /var/log/apache2/error.log
For Nginx servers, use:
tail -f /var/log/nginx/error.log
Look for repeated instances of HTTP 5xx errors, failed connections, or unexpected resets. If the web server is repeatedly restarting or crashing, it may be due to server resource exhaustion, a misconfigured .htaccess file, or malformed requests.
Test Cloudflare Error 520 with cURL Debugging
Using cURL debugging can help identify whether the 520 error is originating from Cloudflare or the origin server. Run the following command in the terminal:
curl -svo /dev/null http://yourwebsite.com/
If the origin web server is not responding correctly or returning empty headers, the issue likely lies with the server configuration. If the server response is normal, then the issue may be related to Cloudflare caching or proxy settings.
Disable Cloudflare and Test Direct Server Response
Temporarily disabling Cloudflare’s proxy helps determine if the 520 error originates from Cloudflare or the server itself. Log into Cloudflare, go to the DNS settings, and switch the Proxy status from “Proxied” to “DNS Only.”
Alternatively, go to Overview > Advanced Actions > Pause Cloudflare. After making this change, clear your browser cache and check if the website loads properly. If the error persists, the problem is likely on the web server. If the website loads fine, re-enable Cloudflare and check for misconfigurations in its settings.
Verify SSL/TLS Certificate and Security Settings
Conflicting SSL/TLS configurations between Cloudflare and the origin server can cause HTTP 520 errors. If Cloudflare is set to Full (Strict) SSL mode, but the origin server does not have a valid SSL certificate, Cloudflare will block the request.
To check SSL settings, go to Cloudflare Dashboard > SSL/TLS > Overview. If using Full (Strict) mode, ensure that the origin server has a properly installed SSL certificate. If the certificate is expired or improperly configured, either renew the certificate or switch to Full (not Strict) mode in Cloudflare.
Additionally, verify that the SSL certificate chain is correctly configured. Running an SSL test on services like SSL Labs can identify any certificate-related issues.
Preventing Cloudflare 520 Errors in the Future
Regular server maintenance and monitoring can help prevent Error 520 from reoccurring. Keeping server software, plugins, and security tools updated ensures compatibility with Cloudflare’s latest protocols.
Whitelisting Cloudflare’s IP addresses in firewall settings prevents unintended request blocking. Additionally, monitoring server logs and conducting regular performance checks helps detect server overloads or connection timeouts before they cause issues.
Using Cloudflare Analytics to monitor HTTP request failures and configuring Cloudflare’s Rate Limiting feature can also help mitigate sudden spikes in server resource usage.
Conclusion: Resolving Cloudflare Error 520
The Cloudflare 520 error occurs when Cloudflare fails to receive a valid response from the origin web server. Fixing this issue requires checking DNS settings, server response headers, firewall rules, SSL configurations, server logs, and network connectivity.
If the issue persists, temporarily disabling Cloudflare’s proxy mode or running cURL debugging can provide further insights. Contacting Cloudflare support with relevant HAR file logs and Ray IDs can also help resolve complex cases.
By proactively monitoring web server performance, ensuring proper SSL configurations, and whitelisting Cloudflare IP addresses, website owners can prevent Cloudflare 520 errors and maintain optimal website availability.
Visit Our Post Page: Blog Page