How to Fix Error 521 with WordPress and Cloudflare

error 521

In this guide, learn how to fix error 521 with WordPress and Cloudflare

Errors can occur in any website that communicates with a server or hosting provider. The status code associated with an error can be helpful when debugging the error.

If you encounter a 521 error on your WordPress website, then there is likely an issue with the web server, preventing it from displaying the web page.

This is a common error that can occur on any website, including WordPress powered websites. In this guide, we will focus on how to fix error 521 with WordPress and Cloudflare.

Content:

What is Error 521?

521 Error, also known as server not found is an error specific to websites hosted with Cloudflare. It is similar to the 504 gateway error but differs in terms of issues causing the error.

It essentially means, your web browser and Cloudflare connected properly. However, Cloudflare was unable to connect to the server of your website.

In a more common term, Cloudflare requests access to your WordPress sites’ server, but the host server is blocking Cloudflare’s IP address, hence displaying the Cloudflare error 521 page as seen in the image below.

error 521
 

Common Causes of Error 521 with WordPress and Cloudflare

On WordPress sites, a 521 web server is offline error can occur due to a variety of reasons, we’ve outlined three common causes of this error below.

Firstly, the Host web server configuration might not be properly set, thus preventing Cloudflare from retrieving data from the server. This often occurs when the origin web server process eg, Apache or Nginx is not running or has crashed.

Once there is an error with the origin server, you would still encounter a 521 server is an offline error on your website even though other settings are properly set.

Secondly, a 521 error can occur if your website’s host is blocking requests from Cloudflare’s servers. Cloudflare uses a reverse proxy to transfer packets from the origin server.

This means, when someone tries to access your website from their device, the request passes through Cloudflare. The host server will only see requests from Cloudflare not from individual IP Addresses of your websites’ users.

Some web hosts’ security solutions might mistake large requests from a single IP address as an attack on the server. In such a scenario, a 521 server down error will occur.

Lastly, if you are moving your DNS to Cloudflare and configure the SSL to “full access” on the SSL/TCP tab, It might raise a 521 server down error because the origin server is refusing Cloudflare’s request on port 443.

How to Fix Error 521 with WordPress and Cloudflare

Confirm that the WordPress Websites’ Origin Server is Configured Properly

This first step of troubleshooting is important because the web server or hosting needs to be up and running, otherwise, there is no point in checking other causes.

If the webserver processes are not running properly, then this is what is causing the error. You can determine this by checking the header and reading any error messages.

Checking for Server Errors with HTTP Header Checker

To test your origin server, you can test with telnet via a remote desktop client, or even simpler – using the cURL command on your terminal window.

We will be showing you how to use the cURL option.

Luckily, there is an online cURL tool that takes all the hard work away from you.

Simply enter your websites’ domain name as seen below to test with curl.

Click on the Check button when done. If all is working properly on the server, you should get a 200 success response displayed on the screen.

If you also encounter a 301 or 404 response when you check your website, the server is running properly.

A 301 response means you have set a redirect for the domain of your website, while a 404 response means the index page of your website cannot be found on the database server configuration.

However, if it displays a 500 response, the server configuration is faulty, preventing Cloudflare from establishing a connection with your WordPress hosting.

For a full guide on fixing this error, see this article: How to Fix 500 Internal Server Error in WordPress.

However, we’ll be touching on the most common causes of this below. First, you may need to increase your memory limit in the wp-config file on your Host server. If that doesn’t fix it, you will need to ensure your plugins are not the source of the error.

How to Fix Memory Limit via wp-config File: Fixing error 521 with WordPress and Cloudflare

Login to the control panel of your website (we’re using cPanel in this example, but the steps are similar in others). Once logged in, click on File Manager >> public_html

Right-click on the wp-config file as seen in the image below.

File manager: fix error 521 with wordpress and cloudflare

Click on Edit to update the content of the file. (Ensure you backup/download before making any changes).

In the wp-config file, search for this command  WP_MEMORY_LIMIT using CTRL+F and increase to about 64MB. You should have a line of code similar to the one below.

define(‘WP_MEMORY_LIMIT’, ’64M’);

Save the changes, then visit your site to check if the error has been resolved.

Alternatively, you can fix the 500 internal server error by deactivating all plugins in the wp-admin dashboard.

If the error stops showing after deactivating all plugins, then begin reactivating each plugin one at a time to find the plugin responsible for the error. Once you locate the plugin, ensure you permanently delete it.

Read this guide for further information: How to Disable WordPress Plugins Using FTP.

However, if you are still seeing the error after troubleshooting using the steps above, you may need to contact your hosting provider for further guidance.

Whitelist all Cloudflare IP Address in the Origin server of your Website

As mentioned above, Cloudflare handles all requests on a specific IP and sometimes creates a large number of requests. Serverside security solutions might mistake the increase in traffic from Cloudflare’s IPs as an attack on the server, leading to Cloudflare IPs being blocked.

If the origin host of your website has security solutions blocking Cloudflare’s requests, then you’ll be able to fix error 521 with WordPress and Cloudflare by updating the server to allow Cloudflare IP ranges. Here is a set of Cloudflare IPs used by most WordPress sites.

You can find the whitelist settings either in the .htaccess config file, the iptable file, or the firewall of the Host server. To whitelist Cloudflare IP ranges in your servers, you need to modify the .htaccess file. Here’s how:

Login to the cPanel of your WordPress hosting or VPS hosting (depending on the one your site uses).

After that, go to File manager >> public_html.

Then right-click on the .htaccess file and select Edit (Ensure you backup/download the file before making any changes)

fix error 521 with wordpress and cloudflare

Paste the following code snippet on the file.

<RequireAny>

Require all granted

Require ip 127.0.0.1

</RequireAny>

Replace 127.0.0.1 with the IP address you wish to whitelist. In this case, Cloudflare’s IP address.

To whitelist multiple IP addresses, enter a new line, add the Require ip 127.0.0.1 command, and replace with the correct IP accordingly.

Save the file with new server IPs.

NOTE: If you cannot locate the .htaccess file on your Cpanel, click on Settings >> Select show hidden files >> Save.

fix error 521 with wordpress and cloudflare

Set your Website SSL to Flexible SSL

If your website is using Cloudflare’s servers, setting the Cloudflare SSL certificate to “Full SSL” sometimes disrupts the website’s connection to the server and displays a standard 521 Cloudflare error. To fix this, set the SSL to “flexible SSL”. Here’s how:

Login to your Cloudflare account.

Click on the SSL/TCS tab on your website domain settings. Update to Flexible SSL.

fix error 521 with wordpress and cloudflare

 

Conclusion – How to Fix Error 521 with WordPress and Cloudflare

In this post, we have covered the basics of the 521 error, a few causes of the error, and a descriptive guide on How to Fix Error 521 with WordPress and Cloudflare.

If you are still unable to access your WordPress site after applying the steps above, you can contact your host or hire an expert to help you troubleshoot and fix the error.