How to Fix Error 521 with WordPress & Cloudflare

Error-521

When your web server, prevents your website from displaying the web page you would encounter the error 521. This is can be on the WordPress website as well. A website hosted in Cloudflare faces error 521 when the server is not found upon request and is unable to connect to the server of your website.

Check your host web server configuration is set properly not. This prevents Cloudflare from retrieving data from the server. The 521 server is an offline error on your website even if other settings are set properly.

To check if your website’s host is blocking requests from Cloudflare’s servers, as Cloudflare uses a reverse proxy to transfer packets from the origin server, this implies that when you try to access the device it passes through the Cloudflare. The host server takes the requests from Cloudflare and not from the individual IP Addresses of your websites’ users.

Another reason you could face error 521 is that when you move DNS to Cloudflare and then configure the SSL to “full access” on the SSL/TCP tab. This is because the origin server refuses Cloudflare’s request on port 443.

Steps to fix error 521:

The first and most step is to keep your web server or hosting up and running, and if the webserver processes are not running properly, then this can be the reason for the error which can be seen in the header.

Using HTTP Header Checker to Check for Server Errors

Let’s test the origin server using telnet via a remote desktop client, or even easier with the cURL command in your terminal window.

To test curl, simply type the domain name of your website in the URL tab. Once you’re done, click the Check button. If it’s working well on the server, you will get a 200 success response on the screen. When you check your website, if you get a 301 or 404 response, the server is functional.

A 301 response redirect for your website’s domain, but a 404 response index page of your website cannot be located on the database server settings.

If it sends a 500 response, the server setup is misconfigured, preventing Cloudflare from connecting to your WordPress hosting. To begin, you may need to increase the RAM limit in your Host server’s wp-config file. If it doesn’t work, make sure your plugins aren’t the source of the problem.

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

  • Login into your website’s control panel.
  • Click File manager >> public_html.
  • Right-click wp-config file >> Edit to update the file (Before making any changes, be sure to backup/download).
  • Using CTRL+F, find the command WP MEMORY LIMIT in the wp-config file and increase it to around 64MB. You will see the following line of code similar to the below one.
define(‘WP_MEMORY_LIMIT’, ’64M’);
  • Save and check your site if the errors have been resolved.

Another method to resolve the 500 internal server problem is by deactivating all plugins in the wp-admin dashboard. If the issue resolves after deactivating all plugins, reactivate each plugin one at a time until you locate the source. When you’ve found the plugin, make sure to remove it permanently.

If the error still occurs even after following the troubleshooting procedures described above, then you can contact your hosting provider for more assistance.

Whitelist all Cloudflare IP addresses in your website’s origin server

As previously stated, Cloudflare processes all requests on a given IP address and often generates a large number of requests. Server-side security solutions may misinterpret the increased traffic from Cloudflare IPs as an attack on the server, resulting in Cloudflare IPs being blocked.

If your website’s origin host has security solutions that prevent Cloudflare requests, you may resolve 521 errors with WordPress and Cloudflare by upgrading the server to enable Cloudflare IP ranges. The whitelist settings can be found in the .htaccess configuration file, the iptable file, or the Host server’s firewall. To whitelist Cloudflare IP ranges on your servers, edit the .htaccess file.

Let us see how it works:

  • Log into your WordPress hosting or VPS hosting’s cPanel (depending on your site uses).
  • Go to File manager >> Public_html.
  • Right-click wp-config file >> Edit to update the file (Before making any changes, be sure to backup/download).
  • Copy and paste the following code into the file.
<RequireAny>
Require all granted
Require ip 127.0.0.1
</RequireAny>
  • Now replace 127.0.0.1 with the IP address you would like to whitelist. Cloudflare’s IP address is used in this case.
  • Then to whitelist multiple IP addresses, start a new line, add the require ip 127.0.0.1 command, and change the IP address with the correct one.
  • Save the file with the updated server IP addresses.

Note: If you can’t find the .htaccess file on your Cpanel, go to Settings >> Show Hidden Files >> Save.

Now Set your Website SSL to Flexible SSL

In this step, you will need to set the SSL to “flexible SSL”. This is because setting the Cloudflare SSL certificate to “Full SSL” sometimes can disrupt the website’s connection to the server and it displays a standard 521 Cloudflare error, while your website is using Cloudflare’s servers.

You can do that by logging into your Cloudflare account and then clicking on the SSL/TCS tab on the domain settings and then choosing the ‘Flexible SSL’ option.

You can try these steps to fix error 521 with WordPress and Cloudflare and if in case you couldn’t fix it, you can get assistance.

To get more updates you can follow us on Facebook, Twitter, LinkedIn

Subscribe to get free blog content to your Inbox