How to fix Cloudflare “Error 520: web server returns an unknown error”

Cloudflare error 520 - How to fix it

Have you ever encountered the “Error 520: web server returns an unknown error” while using Cloudflare with your website? This error message indicates that Cloudflare could not connect with the origin server. This error can be caused by various issues, including unexpected, empty, or unknown responses from the origin server. This article will discuss the reasons for the 520 error and how to resolve it.

Workaround to Fix Cloudflare Error 520

One quick workaround while investigating the reason for the 520 error is to either make the record DNS-only in the Cloudflare DNS app or temporarily pause Cloudflare. This will help determine if the issue is related to Cloudflare or the origin server.

It is essential to contact your hosting provider or site administrator if you encounter a 520 error. Request a review of your web server error logs for crashes and fatal errors. Common reasons may be responsible for the error, such as origin web server application crashes, Cloudflare IPs not allowed at your origin, headers exceeding 16 KB, or an empty response from the origin web server that lacks an HTTP status code or response body.

Another reason for the error is missing response headers or the origin web server not returning proper HTTP error responses. If the upstream prematurely closed connection while reading the response header from the upstream, it may cause Cloudflare to generate 520 errors.

Some PHP applications can cause the origin web server to crash, which results in 520 errors. If you are using a PHP application, keeping it up-to-date with the latest version and patches is essential.

If the 520 errors persist after contacting your hosting provider or site administrator, you can provide the following information to Cloudflare Support to help you resolve the issue:

  • Full URL(s) of the resource requested when the error occurred
  • Cloudflare cf-ray from the 520 error message
  • Output from http://www.example.com/cdn-cgi/trace (replace www.example.com with your hostname and domain where the 520 error occurred)
  • Two HAR files: one with Cloudflare enabled on your website and the other with Cloudflare temporarily disabled.

The HAR files will provide detailed information about the network activity between the browser and server, including HTTP headers, response codes, and timing information. This information can help Cloudflare Support diagnose and fix the issue.

In conclusion, the “Error 520: web server returns an unknown error” can be caused by various issues, such as origin web server crashes, Cloudflare IPs not allowed at your origin, headers exceeding 16 KB, or an empty response from the origin web server. If you encounter this error, contacting your hosting provider or site administrator is crucial to resolve the issue. In addition, providing detailed information to Cloudflare Support will help resolve the error and prevent it from recurring. Remember to try the quick workaround of making the record DNS-only or pausing Cloudflare as you investigate the issue further.

Related Articles

  1. Curl Error 35 Unknown SSL Protocol Error in Connection
  2. How to fix the Error establishing a database connection in WordPress

Updated on February 19, 2023