How to Fix Cloudflare Error 520
Cloudflare Error 520, marked as "Web Server Returns an Unknown Error," is a specific issue that arises when there are complications at the origin server. Having already discussed other Cloudflare errors like 500 and 523, let’s delve into the 520 error in more detail. This error occurs when the server sends a response that Cloudflare cannot understand or doesn't expect. Common causes for this issue include application crashes, blocked IPs, excessive cookies, and unusual error responses from the origin server. Below, we’ll break down these causes and offer solutions to resolve the error.
If the application on your origin server, which handles Cloudflare's requests, experiences a crash, the result could be the 520 error. This could be triggered by issues like faulty plugins, a failed update, or an unexpected server glitch. For instance, on a WordPress site, a crash could happen due to plugin misconfigurations or server malfunctions. The best course of action is to examine the WordPress debug logs. For non-WordPress apps, you should check the application’s specific debugging tools.
It’s a good practice to have a debugging system in place to capture potential issues before they disrupt your site. Storing logs for a few days is generally sufficient to troubleshoot and fix any application-related problems.
Cloudflare functions as a proxy between your visitors and the origin server, so it’s crucial that your server allows Cloudflare’s IPs to connect. If the server blocks Cloudflare's IPs, you may experience the 520 error. This issue is more likely to occur if your server has a custom firewall configuration, especially now that Cloudflare’s integration with cPanel has been reduced. It’s important to check whether your server is blocking Cloudflare's IPs. You can consult an updated list of Cloudflare IPs for reference.
While not explicitly stated in the official documentation, Cloudflare seems to have a limit on response headers, specifically those exceeding 16 KB in size. One of the factors contributing to this issue is the presence of too many cookies. Although cookies themselves might not fill up 16 KB, they can add up, especially when combined with other response header elements. Browsers and network devices generally limit cookies to around 4 KB, but when there are too many, the total size of the headers can breach Cloudflare's limit.
The complexity of this issue lies in the fact that not all requests will set the same number of cookies. Once cookies are stored in the user’s browser, they don’t need to be sent again. So, if you can’t pinpoint the issue, start by examining your cookies.
Certain PHP applications can return strange error codes that don’t align with standard HTTP response codes. For example, if a plugin on your site generates an unrecognized response code, Cloudflare may trigger a 520 error. For reference, Cloudflare expects responses to fall within the standard HTTP status code range. Anything out of the ordinary could result in this error.
If after checking your server you can’t identify the issue, it’s time to reach out to Cloudflare support. Although their documentation may not explicitly mention the 520 error, you can still open a support ticket to get help.
To report a 520 error to Cloudflare, click the "Support" link on their website and provide detailed information about the issue. It’s important to note that live chat support is only available to Business users, not to Pro users.
While waiting for a response, you may want to disable Cloudflare on your domain by changing your DNS settings to "DNS Only" (represented by a gray cloud icon). This step can help mitigate the issue temporarily.
Here’s what you should send to Cloudflare to assist them in debugging the issue:
A. CF-RAY Number: The CF-RAY number is a unique identifier for each Cloudflare response. To extract it, use your browser's developer tools. Under the "Network" tab, refresh the page, and look for the CF-RAY number in the first resource listed (your page URL). Send this number along with your support request.
B. HAR Files: HAR (HTTP Archive) files contain detailed logs of the entire connection between your browser and Cloudflare, offering a closer look at what happened during the request. To generate a HAR file, open the developer tools in Chrome or Firefox and save the network logs. These files provide Cloudflare with detailed information, including connection times and any redirects, which will aid in troubleshooting.
C. Trace Information: The trace output from Cloudflare’s special URL (https://www.yourdomainname.com/cdn-cgi/trace) is another useful piece of information. Replace “yourdomainname” with your actual domain and collect the trace data to send to Cloudflare along with the CF-RAY number and HAR file.
Review your server and reverse proxy configurations to ensure they follow standard HTTP practices. Look for any settings that could cause ambiguous responses or miscommunication between the origin server and the proxy.
Review your firewall and security settings to ensure they are not blocking or altering responses from the origin server. Whitelist known proxy IPs to prevent unintentional blocking.
Use tools like traceroute or network monitoring software to detect network issues that could be causing the 520 error. Optimizing network routes and reducing timeouts can help ensure smooth communication between servers.
Regularly monitor the origin server's performance to ensure it is not overwhelmed by traffic. Consider implementing load balancing or upgrading server resources to handle peak demand.
Ensure that your SSL/TLS certificates are valid and properly configured. Regular checks and timely renewals can prevent certificate-related conflicts that may trigger a 520 error." into chinese.
Cloudflare 5xx errors, such as the 520 error, can often stem from issues on your origin server, but sometimes Cloudflare itself may be at fault. Debugging these errors can be tricky, as there is no clear mapping between specific server issues and error codes. If you suspect the issue lies with Cloudflare, follow the steps outlined above, set Cloudflare to "DNS Only," and wait for a response from support.
By sending Cloudflare the necessary information and patiently working through the troubleshooting steps, you’ll increase the chances of resolving the error and getting your site back up and running smoothly.