Error 520: What It Means and How to Fix It

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.

How to fix Error 520

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: 

  1. Log in to your Cloudflare account. 
  2. Navigate to the Overview tab in the left-hand panel.
  3. Scroll down to the Advanced Actions section and select Pause Cloudflare on Site
How to pause Cloudflare to troubleshoot error 520.

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: 

  1. Log in to Cloudflare.
  2. Select the website that outputs the error 520.
  3. In the left-hand menu, select DNS > Records.
How to locate Cloudflare 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:

  1. Open the web page displaying the 520 error.
  2. Right-click and select Inspect.
Inspect page to generate HAR file.
  1. Select the Network tab.
  2. Check the Preserve log option.
  3. Click the Clear (stop sign) button.
Setting up the Google Chrome browser to generate a HAR file
  1. Reload the page.
  2. Right-click anywhere in the area below the nav bars of the inspect tool.
  3. Select Save all as HAR with content.
How to save a HAR file.

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.

Was this article helpful?
YesNo
Mirjana Fodora
Mirjana Fodora is a Technical Writer with a background in Web Design and Development. Despite being one of the youngest members on the team, her writing skills and technical aptitude help her produce factual, informative, and user-friendly content.
Next you should read
Troubleshooting DNS Issues {nslookup, dig, host & More}
November 17, 2021

DNS (domain name system) stores information related to domain names as a distributed database. The client-server service translates domain names to IP addresses and vice versa.
Read more
Localhost Refused to Connect - How to Fix the Error
May 16, 2024

Localhost refused to connect is a common error that may occur when working on a local machine. In this article, you will learn the most common causes of the localhost refused to connect error...
Read more
How to Troubleshoot ERR_TOO_MANY_REDIRECTS
March 3, 2022

The ERR_TOO_MANY_REDIRECTS error occurs when the browser is redirected to a different URL, which in turn points back to the original one, creating a redirection loop.
Read more
403 Forbidden Error - What Is It and How to Fix It
December 19, 2024

When a web server denies access to a particular webpage or web content, it displays the 403 Forbidden error. Different web servers report different variations of the 403 Forbidden error...
Read more