Introduction
Cloudflare's error 520 is a complex error code indicating that a webpage cannot be reached. The complexity of the issue lies in the variety of reasons that could have caused it.
Becoming familiar with potential causes is the key to streamlining the troubleshooting process.
This article explains what the error means, why it occurs, and how to troubleshoot and resolve it.
What Is Error 520?
Error 520 is a Cloudflare error message indicating that the origin web server received an invalid or incorrectly interpreted request, resulting in an empty response.
What Causes Error 520?
The most common causes for error 520 are:
- PHP applications crashing.
- Incorrectly configured DNS records.
- Corrupt or incorrectly configured .htaccess file.
- Large request headers and excessive cookie usage.
- Missing request headers.
- Empty response from server.
How to Troubleshoot and Fix Error 520
The following steps outline the process of investigating the cause behind Cloudflare's error 520, so appropriate action can be taken accordingly.
Note: Before attempting the following methods, check that the affected website is completely inaccessible and that Cloudflare’s system status is “All Systems Operational”.
1. Pause Cloudflare
If the issue lies in Cloudflare, pausing it will make the page affected by the error accessible again.
To pause Cloudflare:
- Log in to your Cloudflare account.
- Navigate to the Overview tab in the left-hand panel.
- Scroll down to the Advanced Actions section and select Pause Cloudflare on Site.
2. Check DNS Records
Domain Name System (DNS) records are files in authoritative DNS servers that specify:
- What IP address is associated with a domain.
- How to handle incoming requests for that domain.
For Cloudflare to work properly, Cloudflare DNS records must match the ones in the domain’s DNS management system.
To locate Cloudflare’s DNS records for a website:
- Log in to Cloudflare.
- Select the website that outputs the error 520.
- In the left-hand menu, select DNS > Records.
The exact steps to access a domain’s DNS settings depend on the website’s hosting platform.
3. Restart PHP
Error 520 occurs also when a PHP application crashes. In that case, restarting the web server hosting the website fixes the issue.
Depending on your software stack, PHP can be restarted in several ways. Below are instructions on how to restart an Apache or Nginx server on different operating systems.
Apache Web Server
To restart an Apache server running on an Ubuntu or Debian system, run:
sudo systemctl restart apache2
To restart an Apache server running on a CentOS 7 system, run:
sudo apachectl -k restart
Nginx Web Server
To restart an Nginx server gracefully, run:
sudo systemctl reload nginx
To force restart an Nginx server, run:
sudo systemctl restart nginx
Alternatively, to force close and restart Nginx and related processes, use:
sudo /etc/init.d/nginx restart
Some hosting platforms allow users to restart PHP using a graphical user interface (GUI). In that case, consult the hosting platform’s user manual or contact the customer support department.
4. Check Headers and Cookies
The maximum allowed size of Cloudflare’s request headers is 32 KB, 16 KB per individual header. Exceeding these thresholds may cause the 520 error to occur.
Information regarding the request headers’ size is available in the origin server’s HAR (HTTP Archive) file.
To generate and extract a HAR file using Google Chrome:
- Open the web page displaying the 520 error.
- Right-click and select Inspect.
- Select the Network tab.
- Check the Preserve log option.
- Click the Clear (stop sign) button.
- Reload the page.
- Right-click anywhere in the area below the nav bars of the inspect tool.
- Select Save all as HAR with content.
The process of generating a HAR file is almost identical between different major web browsers since they are all built upon Chromium (except Firefox).
Examining HAR files is only possible with software like Google’s HAR Analyzer.
Important: HAR files contain sensitive information, such as cookies, passwords, and other types of personal data. Remove any compromising data before sharing HAR files with anyone.
The anomaly to look for in HAR files is cookies that are too large and the overall excessive use of cookies.
To reduce cookie size and lighten the request header load:
- Remove unnecessary third-party plugins from the website.
- Limit request overhead.
- Use a cookie-free domain.
5. Disable .htaccess
The .htaccess file affects the global configuration of an Apache server without changing the configuration files.
Error 520 can appear when a redirect was not configured properly in the .htaccess file, or the file itself is corrupted. Disabling the .htaccess file will reveal whether the file is problematic.
1. To disable the .htaccess file, start by opening the apache2.conf file in a text editor (we are using nano):
sudo nano /etc/apache2/apache2.conf
The default location for the Apache config file is one of the following:
- /etc/httpd/httpd.conf
- /etc/apache2/httpd.conf
- /etc/apache2/apache2.conf
- /etc/httpd/conf/httpd.conf
2. Find the value of the AllowOverride
directive and change it to None.
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
3. Save and close the file.
4. To apply the changes, restart Apache:
sudo systemctl apache2 restart
Note: For more information on .htaccess setup and configuration, refer to our guides How to Enable & Set Up .htaccess File on Apache and How to Create & Edit the Default WordPress .htaccess File.
6. Check Web Server Error Logs
Error logs provide additional information about where, why, and what error occurred.
The process of locating or generating error logs varies between hosting providers. However, all error logs feature a similar structure and will provide the following information:
- The date and time of the incident.
- The IP address of the client (if the client caused the error to happen).
- An error message.
- A path to the affected resource or the line of code causing the issue.
7. Check HTTP Error Response with a cURL Command
Client URL (cURL) commands allow users to get information about the HTTP error response code and request headers.
The general syntax is:
sudo curl -svo /dev/null https://yourwebsitehere.com
A successful response will look like the following example:
* Trying 111.11.1.111...
* Connected to 111.11.1.111 (111.11.1.111) port 100 (#0)
> GET /login HTTP/1.1
> User-Agent: YourBrowser 1.0
> Accept: */*
> Host: examplewebsite.com
>
< HTTP/1.1 200 OK
< Content-Type: text/html
< Date: Day, DD, Month Year Hour:Minute:Second Timezone
{ [11111 bytes data]
* Connection #0 to host 111.11.1.111 left intact
However, the command will not be able to retrieve information if the 520 error has occurred, and the result will look similar to the following example:
* Trying 111.11.1.111...
* Connected to 111.11.1.111 (111.11.1.111) port 100 (#0)
> GET /login HTTP/1.1
> User-Agent: YourBrowser 1.0
> Accept: */*
> Host: examplewebsite.com
>
* Empty reply from server
* Connection #0 to host 111.11.1.111 left intact
8. Contact Cloudflare Support
If none of the previous methods helped locate the source of the issue, contacting Cloudflare support is the next step.
Cloudflare offers two support methods:
- Support tickets – available to all accounts and accessible via the admin dashboard.
- Live chat – available to Business and Enterprise accounts only.
In both cases, representatives will request the following information:
- URL(s) of the affected resource(s)
- Cloudflare's Ray ID from the affected resource(s)
- The result of entering the following URL in a browser http://example.com/cdn-cgi/trace (replace example.com with the right domain)
- A HAR file from when Cloudflare was enabled on the website
- A HAR file from when Cloudflare was disabled on the website
Conclusion
Discovering and resolving errors quickly is paramount to reducing downtimes and ensuring positive user experiences.
Use the information in this guide to prevent, troubleshoot, and resolve 520 errors.
Besides error 520, websites using Cloudflare's CDN can display a variety of other error messages, a common one being 521: Web server is down. Read our guide to find out what error 521, error 523, error 524, 504 Gateway Timeout or 526 Invalid SSL Certificate error means and how to troubleshoot and fix it.