How to Fix Error 520: Web Server Is Returning an Unknown Error - Website Vidya (2024)

Table of Contents[Hide][Show]
  • What Is Error 520?
  • What Causes Error 520?
  • How to Fix Error 520?+
    • 1. Temporarily Disable Cloudflare:
    • 2. Verify DNS Records
    • 3. Restart PHP and Web Server
    • 4. Disable .htaccess
    • 5. Check Headers and Cookies
    • 6. Check Web Server Error Logs
    • 7. Check HTTP Error Response with a cURL Command
    • 8. Contact Cloudflare Support
  • Other Error Fixes
  • Conclusion

How to Fix Error 520? It’s a frustrating and complex error code. It indicates that the web page is not reachable. There could be several reasons behind this error code 520. This article covers, what this error code means, why it occurs and how to troubleshoot it.

What Is Error 520?

How to Fix Error 520: Web Server Is Returning an Unknown Error - Website Vidya (1)

Error 520 is an HTTP status code that is typically displayed when a web server returns an empty or incomplete response to the client, or when the server takes too long to respond. This error is often associated with Cloudflare, a content delivery network (CDN) and DDoS protection service.

In the context of Cloudflare, a 520 error indicates that the server (where the website is hosted) is unable to send a valid response to Cloudflare within a certain timeframe. This could be due to various reasons, such as server overload, network issues, or misconfigurations.

What Causes Error 520?

Error 520 can occur due to various reasons, with the following being the most prevalent:

PHP Applications Crashing: When PHP applications on the server crash, it can trigger an Error 520.

Incorrectly Configured DNS Records: Misconfigurations in DNS records may lead to the generation of the 520 error.

Corrupt or Incorrectly Configured .htaccess File: Issues with the .htaccess file, such as corruption or incorrect configurations, can contribute to the occurrence of Error 520.

Large Request Headers and Excessive Cookie Usage: If the size of request headers is substantial, or there’s an excessive use of cookies, it may result in the server returning a 520 error.

Missing Request Headers: In cases where necessary request headers are missing, the server might fail to respond appropriately, leading to the error.

Empty Response from Server: When the server fails to provide a valid response or returns an empty response, it can trigger the 520 error.

How to Fix Error 520?

1. Temporarily Disable Cloudflare:

If the root cause of the issue is within Cloudflare, temporarily disabling it can restore accessibility to the affected page.

To disable Cloudflare temporarily:

  • Log in to your Cloudflare account.
  • Head to the Overview tab in the left-hand panel.
  • Scroll down to the Advanced Actions section and choose “Pause Cloudflare on Site.”

By temporarily pausing Cloudflare, you can isolate whether the problem is related to the CDN service, and this step may assist in troubleshooting and resolving the underlying issue.

2. Verify DNS Records

Domain Name System (DNS) records, residing in authoritative DNS servers, play a crucial role in defining:

  • The association of an IP address with a domain.
  • Protocols for managing incoming requests to that domain.
  • It’s imperative for Cloudflare’s seamless functionality that its DNS records align with those in the domain’s DNS management system.

To check Cloudflare’s DNS records for a website:

  • Log in to your Cloudflare account.
  • Choose the specific website encountering the error 520.
  • Navigate to the DNS section by selecting DNS > Records in the left-hand menu.
  • Ensuring the synchronization of DNS records is essential for proper communication between Cloudflare and the domain, minimizing the likelihood of encountering error 520.

3. Restart PHP and Web Server

Error 520 may also manifest when a PHP application crashes. Resolving this issue often involves restarting the web server hosting the website.

For various software stacks, PHP can be restarted through different methods. Below are instructions for restarting Apache or Nginx servers on various operating systems.

Apache Web Server

Restart the Apache server on Ubuntu or Debian systems, by running:

sudo systemctl restart apache2

On CentOS 7, restart the Apache server with:

sudo apachectl -k restart

Nginx Web Server

Gracefully restart an Nginx server by running:

sudo systemctl reload nginx

Forcefully restart Nginx with:

sudo systemctl restart nginx

Alternatively, force close and restart Nginx and related processes using:

sudo /etc/init.d/nginx restart

For users on hosting platforms with a graphical user interface (GUI), PHP may be restarted through platform-specific tools. Refer to the hosting platform’s user manual or contact customer support for guidance in such cases.

Restarting the PHP and web server components can often resolve issues associated with PHP application crashes, mitigating the occurrence of Error 520.

4. Disable .htaccess

The .htaccess file wields influence over the global configuration of an Apache server, providing a means to adjust settings without altering core configuration files.

Error 520 may keep on appearing if the file itself is corrupted or if a redirect is improperly configured in the .htaccess file. Disabling the .htaccess file can help us diagnose the issue.

To disable the .htaccess file, follow the steps below:

Open the apache2.conf file in your favourite text editor:

sudo vim /etc/apache2/apache2.conf

The Apache config file may be located at one of the following default paths:

/etc/httpd/httpd.conf
/etc/apache2/httpd.conf
/etc/apache2/apache2.conf
/etc/httpd/conf/httpd.conf

Locate the value of the AllowOverride directive and modify it to “None.”

 Options Indexes FollowSymLinks MultiViews AllowOverride None Require all granted

Save and close the file.

Apply the changes by restarting Apache:

sudo systemctl restart apache2

Disabling the .htaccess file through these steps aids in troubleshooting, helping identify whether issues stem from this configuration file. Remember to reevaluate and adjust configurations once the root cause is determined and resolved.

5. Check Headers and Cookies

Error 520 can arise if the size of Cloudflare’s request headers surpasses the allowable limit of 32 KB, with an individual header limit of 16 KB. To troubleshoot and address this issue, inspecting the size of request headers in the origin server’s HAR (HTTP Archive) file is crucial.

Here’s how 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.”

3. Navigate to the Network tab.

4. Enable the “Preserve log” option.

5. Click the Clear (stop sign) button.

6. Reload the page.

7. Right-click below the navigation bars of the inspect tool.

8. Choose “Save all as HAR with content.”

This process is nearly identical across major web browsers based on Chromium (except Firefox).

HAR files can be analyzed using tools like Google’s HAR Analyzer. Keep in mind that HAR files contain sensitive data, such as cookies and passwords. Remove compromising information before sharing HAR files.

Examine HAR files for anomalies, particularly large cookies and overall excessive cookie usage. To address this:

  • Remove unnecessary third-party plugins from the website.
  • Limit request overhead.
  • Consider using a cookie-free domain.

By scrutinizing and optimizing headers and cookies, you can potentially alleviate the occurrence of Error 520 and enhance the performance of your web application.

6. Check Web Server Error Logs

Error logs play a crucial role in gaining deeper insights into the occurrence, origins, and nature of errors. They offer valuable information about the specifics of an error, aiding in effective troubleshooting.

While the procedure for accessing or generating error logs may differ among hosting providers, the fundamental structure remains consistent. Error logs typically include the following essential details:

  1. Date and Time of Incident: Timestamps provide precise information about when an error occurred.
  2. Client IP Address: If the error is client-induced, the logs often reveal the IP address associated with the triggering event.
  3. Error Message: A concise description of the error, offering insights into its nature and possible causes.
  4. Path to Affected Resource or Line of Code: Crucial details pointing to the location of the error, aiding in pinpointing the root cause.

To harness the power of error logs:

Consult your hosting provider’s documentation for guidelines on accessing error logs.

Look for sections titled “Error Logs” or similar in your hosting control panel.

By regularly checking and interpreting web server error logs, you empower yourself to swiftly identify, understand, and address issues, ensuring the smooth operation of your website or application.

7. Check HTTP Error Response with a cURL Command

Using cURL commands provides a straightforward method to inspect HTTP error responses and request headers. The syntax is as follows:

sudo curl -svo /dev/null https://your_website.com

For a successful response, the output resembles the following:

* 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: your_website.com>

However, in the case of a 520 error, the command won’t retrieve information, and the result will resemble this:

* 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: your_webssite.com>* Empty reply from server* Connection #0 to host 111.11.1.111 left intact

By leveraging cURL commands, you gain valuable insights into the communication between your client and the server, aiding in the diagnosis of HTTP errors such as the elusive 520 error.

8. Contact Cloudflare Support

If all the troubleshooting methods fail to pinpoint the issue, reaching out to Cloudflare support becomes the logical next step.

Cloudflare provides two avenues for support:

  1. Support Tickets: Accessible to all accounts, this method can be initiated through the admin dashboard.
  2. Live Chat: Exclusive to Business and Enterprise accounts, live chat offers real-time assistance.

When contacting Cloudflare support, be prepared to provide the following essential information:

URL(s) of the Affected Resource(s): Indicate the pages or resources experiencing the issue.

Cloudflare’s Ray ID: Obtainable from the affected resource(s), the Ray ID is crucial for support analysis.

Result of Accessing http://your_website.com/cdn-cgi/trace: Replace your_website.com with the correct domain and share the result obtained from this URL in a browser.

HAR File with Cloudflare Enabled: Provide an HTTP Archive (HAR) file captured when Cloudflare was active on the website.

HAR File with Cloudflare Disabled: Similarly, furnish a HAR file captured when Cloudflare was deactivated on the website.

By supplying this comprehensive information, Cloudflare support can expedite the troubleshooting process and offer targeted assistance in resolving the persistent Error 520 issue.

Other Error Fixes

  • How to Fix the HTTP 415 Error on Your Website
  • How to fix “the uploaded file exceeds the upload_max_filesize directive in php.ini.” error
  • How to Fix a 408 Request Timeout Error
  • How to Fix 403 Forbidden Error in NGINX Ubuntu
  • Error Establishing a Database Connection in WordPress Fix
  • Fix 502 Bad Gateway Nginx Error in Ubuntu – 4 Simple Steps
  • Fix 504 Gateway Timeout Nginx Error – 5 Simple Steps
  • PHP5-FPM 502 Bad Gateway Error (connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory)

Conclusion

In conclusion, resolving Cloudflare’s Error 520: Web Server Is Returning an Unknown Error demands a systematic and thorough approach. The provided troubleshooting steps guide users through identifying potential culprits, ranging from server misconfigurations to issues within Cloudflare settings. By examining aspects like DNS records, server logs, request headers, and the .htaccess file, users can isolate and rectify the root cause.

Additionally, tools like cURL commands and HAR file analysis offer insights into the communication between clients and servers, aiding in pinpointing elusive errors. If all else fails, reaching out to Cloudflare support with detailed information ensures personalized assistance.

Ultimately, successfully resolving Error 520 involves a combination of technical understanding, meticulous investigation, and collaboration with support services. Employing these strategies empowers users to not only fix the immediate issue but also enhance the overall stability and performance of their web applications under the protection of Cloudflare.

Share this post:

Share on LinkedInShare on X (Twitter)Share on PinterestShare on FacebookShare on Email

How to Fix Error 520: Web Server Is Returning an Unknown Error - Website Vidya (2024)
Top Articles
Latest Posts
Article information

Author: Duncan Muller

Last Updated:

Views: 6338

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.