Fixing Error 520

How to Fix Error 520: A Comprehensive Overview

Unlike the infamous error 404 that implies the requested resource (webpage) could not be found on its server (webserver), error 520 indicates that there could be a problem with the server itself or with a server-side configuration, or software application that prevents web pages from being returned to visitors’ browsers.

As a website owner, particularly if you’re hosting a WordPress website, you should be concerned about Error 520. This is because it can indicate that visitors cannot access your website due to issues on “your side.”

This can lead to frustrated visitors and potentially lost business.

In this article, we’ll review some of the common causes of Error 520 and provide tips for troubleshooting and fixing the issue.

How Websites are Rendered

To understand error 520 better, let’s take a quick high-level look at how websites and webpages are rendered through web browsers.
Skip this bit if you already know the nuances of how websites are rendered.

Or, if you’re familiar with concepts such as DNS, proxy servers, CDN, SSL handshake, and the like.

When a visitor types in a website URL into the web browser and presses Enter, the browser, first off, sends a DNS query to the Domain Name System (DNS) server. This is usually provided by the Internet Service Provider (ISP).

The DNS server is responsible for translating the website’s domain name (the one you entered in words) into the corresponding IP address of the server the website is hosted on.

The browser then sends a request to the website’s server address (which it received from the DNS server.) The request is relayed to the website server’s (web server’s) firewall.

This is where the request’s journey “through the internet” unfolds to ultimately render the website on the user’s browser.

If the website is protected (or served) by a Content Delivery Network (CDN) like Cloudflare, which is usually the case, the request first goes to the CDN’s servers. These act as forward proxy servers.

The server (also called the edge server) checks its cache to see if it has the requested content. If it does, it sends the content back to the user’s browser. If it doesn’t, it acts as a reverse proxy server and relays the request to the web server hosting the website and its content.

To do so, the reverse proxy server needs to know the IP address of the web server. This is where DNS comes in again.

A Quick Primer on Firewalls and CDN

CDNs are a geographically distributed network of servers (edge servers) that work together to provide fast delivery of internet content. They are designed to serve content to end-users with high availability and high performance.

Cloudflare is a widely used household name of a CDN that provides a range of services, including content delivery, DDoS protection, and web security.

From the purview of the website and the server it’s hosted on, a Firewall creates a barrier between the trusted internal network and untrusted external networks, such as the Internet.

Based on security policies, it monitors and filters incoming and outgoing traffic.

Coming back to how website content is relayed, the request from the CDN goes through the web server’s firewall and into the web server, where it is processed and responded to (with requested content) back to the user’s browser.

It is, in turn, rendered for the user to view.

Now that we have a broad understanding of how websites are rendered let’s look at how they may be obstructed, resulting in error 520.

How Error 520 Occurs

By displaying error 520, the server is essentially saying that it cannot process the request from the user’s browser. Hence, the website is currently unavailable.

Here are some ways it can occur:

PHP Applications Crashing

Sometimes, the website code written in PHP can crash or stop working properly. When this happens, it can cause Error 520 because the server cannot process the request from the web browser.

Incorrectly Configured DNS Records

At any point during the journey of the web browser’s requests, if the DNS records of your website are not set up correctly and in accordance with the web server, the web browser may not be able to find the website’s server, which can cause Error 520.

Corrupt or Incorrectly Configured .htaccess File

An .htaccess file is a configuration file associated with your website code that tells the web server how to handle certain requests. If this file is damaged or has incorrect settings, it can cause Error 520 because the server doesn’t know how to handle the request properly.

Large Request Headers and Excessive Cookie Usage

When a web browser requests a server, it sends along information called “headers,” which include things like cookies (which remember your preferences on a website). If there are too many headers or cookies, it can overload the server and cause Error 520.

Missing Request Headers

In contrast to the above point, sometimes, the web browser may not send all the necessary information to the server when making a request, and it may not be able to process the request correctly.

Empty Response From Server

It can also happen that the web server or the proxies do not send any response back to the browser, resulting in error 520 because the browser wouldn’t know what to do next.

A Firewall Blocking the Connection

Error 520 can occur if there is a firewall or other security measure in place that is blocking the connection between the reverse proxy server and the origin server.

SSL/TLS Handshake Failure

When a user connects to a website over HTTPS, their browser and the web server engage in an SSL/TLS handshake to establish a secure connection. This involves a series of steps to negotiate the encryption settings and exchange keys for encrypting and decrypting data.

Any issue with the SSL/TLS certificate configuration on the origin server can cause a handshake failure with the reverse proxy server and result in Error 520.

For instance, this can happen if the certificate has expired, is misconfigured, or is invalid.

Overloaded Server

Error 520 also arises if the origin server is overloaded and cannot respond to requests from the reverse proxy server.

How to Troubleshoot and Fix Error 520

There is no need to panic when you come across Error 520. There are several ways to identify and troubleshoot the root cause of the error.

Wait it Out

If you encounter an Error 520 while trying to access a website, you should wait a few minutes and refresh the page to see if the issue has been resolved. The error may arise due to temporary network or server issues.

For instance, the server or network may be experiencing a high volume of traffic or temporary overload that causes it to be unable to process requests.

During this time, the server may be fixing the underlying issue or automatically scaling up its resources to handle the increased load. So, it’s only logical that you give it time to start processing requests again.

Pause/Disable Cloudflare Temporarily

If you use Cloudflare as your reverse proxy server, you can temporarily disable Cloudflare to see if the error disappears. If it does, then you’d know the issue lies with Cloudflare and go about troubleshooting the same.

  • Log in to your Cloudflare account
  • Go to the Overview tab on the left-hand panel
  • Scroll down to the Advanced Actions section
  • Click on “Pause Cloudflare on Site” to temporarily disable Cloudflare from your website

Check and UpdateDNS Records

Login to your DNS provider account, the way to which could also be through your hosting provider, Cloudflare, or similar services. Check if the records are correctly configured, particularly the CNAME (Canonical Name) records.

CNAME record tells the DNS resolver to look up the IP address of the domain specified in the CNAME record and use that IP address as the destination for the request.

Depending on the DNS provider, updating the records could take a few minutes to several hours for the changes to take effect globally.

Restart PHP

Log in to your web server or hosting account, and locate the PHP configuration file for your website. It is usually named php.ini or located in a directory named conf.d or php.d.

Edit/review the file and make sure that the settings (such as memory limits, execution time limits, and file upload size limits) are configured correctly.

Enter your server’s command to restart PHP. Sometimes, the way to restart PHP is by restarting the web server itself. The commands vary depending on the type of web server and the software it runs.

Check Web Server Error Logs

Error logs can provide valuable information about an incident or error, such as where and why. Depending on the hosting provider, locating or generating error logs may differ.

Most error logs share a similar structure and offer essential details such as the incident’s date and time, the client’s IP address (if applicable), the error message, and a path to the affected resource or line of code responsible for the issue.

Scrutinize them and try to identify the root cause.

Clear the Website Cache

Clearing a website’s cache deletes the temporary files and data stored on the website’s server, like images, scripts, stylesheets, and other types of website content. This will force the webserver to reload all its content from scratch, which can help resolve errors like Error 520.

Clearing the cache can also cause temporary performance issues, as the website must load all its content again.

It’s essential to weigh the benefits and drawbacks before clearing the cache. Ensure all necessary backups are in place before making any changes to the website’s configuration.

On that note, you may want to clear your browser cache on the off chance that the issue stems from your browser.

Check HTTP Error Response With a cURL Command

Running a cURL command in your command terminal, Windows key + R” and typing “cmd” (Windows) | Applications > Utilities > Terminal (MacOS), simulates a request to your website’s server and receives a detailed response.

The command format is as follows: curl -I http://example.com

By understanding what a successful response and an error response look like after a cURL command execution, you can verify that the web server is configured correctly and responding to requests.

You can also retrieve the server’s HTTP response headers and review the status codes and messages. Leave the review part to the experts (the support team) if you think it may be too much to digest.

Disable .htaccess

If your web server is powered by Apache, which is most likely the case, disabling the .htaccess used to configure web server settings on Apache servers can help resolve Error 520.

You can also verify that Cloudflare IPs are not blocked in .htaccess or your firewall.

The .htaccess (hypertext access) is a configuration file for Apache-hosted sites. For the unacquainted, Apache is a popular open-source web server software.

When there is a conflict between the rules in the .htaccess file and the server settings, or if the file is corrupted, the browser can return Error 520.

Check Headers and Cookies

Large headers and cookies can exceed the maximum allowed size limit of web servers or CDNs (like Cloudflare) which can cause Error 520.

For instance, at the time of writing this piece, the maximum threshold size of Cloudflare’s request headers is 32 KB, 16 KB per individual header.

Here are the steps to check headers and cookies.

  1. Open the web page where you are experiencing the 520 error.
  2. Right-click anywhere on the page and select “Inspect” from the context menu. This will open the developer tools panel.
  3. In the developer tools panel, select the “Network” tab.
  4. Make sure the “Preserve log” checkbox is checked.
  5. Click on the “Clear” button (stop sign icon) to clear any previous network activity.
  6. Reload the page to start capturing network activity.
  7. Right-click anywhere in the network activity area and select “Save all as HAR with content.”
  8. Choose a location on your computer to save the HAR file and click “Save.”

Analyze it to check for any anomalies, such as excessively large cookies or header sizes. If you find large headers and cookies, you can:

  • Remove any unnecessary third-party plugins or scripts from your website
  • Limit the request overhead i.e. the amount of unnecessary data that is transmitted between the client and the server during each request
  • Use a cookie-free domain for your static assets, such as images, CSS, and JavaScript files

WordPress Specific Measures to Addressing Error 520

In addition to the aforementioned steps, here are a couple more that are more specific to WordPress websites.

  • Check the WordPress logs to see if there are any errors that are causing Error 520
  • Disable all plugins to see if Error 520 goes away. Then re-enable the plugins one by one to determine which one is causing the problem

Last But Not Least – Seek Professional Support

Although there are several steps that you as a website owner can take to troubleshoot Error 520, there may be situations when addressing the error is not entirely within your control.

For instance, if the error is caused by a temporary network outage or a server maintenance issue, you may have to wait for the server to come back online or for the hosting provider to fix the issue.

Also, resolving issues caused by a bug or configuration oversight may require technical expertise that is beyond your scope.

You may need to acquire support from their hosting provider, web developer, or other technical experts who have experience in troubleshooting server-side errors.

Do not hesitate to seek help from technical experts. After all, waiting too long to address them can result in lost traffic and potential revenue for the website.