Using a content delivery network (CDN) such as Cloudflare on your WordPress site can help you reduce load times significantly. However, you may occasionally encounter Cloudflare-specific issues, such as the “521 error”. This particular error prevents the platform from connecting to your website, which means you may not be able to access your site either.
In this article, we’ll talk about what Cloudflare error 521 is and what causes it. Then we’ll look at three ways to fix it.
Let’s get to work!
What is Cloudflare error 521?
A CDN like Cloudflare stores cached copies of your website on a network of servers located around the world. When a visitor tries to access your website, Cloudflare “intercepts” that connection and loads a cached copy from the server closest to their location. This approach often results in much faster load times, as well as less work for your site’s main server.
For Cloudflare to work, it must be able to connect to your website’s server. If, for some reason, that server refuses to connect, you will encounter error 521:
By default, Cloudflare will tell you that it cannot connect to your website server because that server is down. However, there are several other potential reasons why the CDN might not be able to connect to your site.
Before we talk about these reasons, it is important to note that the 521 error is not specific to WordPress. You can encounter this error regardless of the content management system (CMS) you use, and on external websites. However, the fact that you’re using WordPress gives you an additional way to solve the problem, which we’ll get to in a minute.
What causes the 521 error in Cloudflare?
As we mentioned earlier, error 521 occurs when Cloudflare fails to establish a connection with your website’s server. Generally, this happens for one of three reasons:
-
- Your website’s server is down
- Your website’s server is down
If you are using a reputable WordPress hosting company, you should have a near perfect uptime (around 99.9%). This means that in most cases, server unavailability is not the primary cause of the 521 error.
-
- Your server is specifically blocking Cloudflare requests
- Your server is specifically blocking Cloudflare requests
Some firewalls block IP addresses they deem suspicious, and Cloudflare requests can be caught in this net.
- There is a problem with your Cloudflare certificate.
Cloudflare can encrypt traffic between your website and its servers using its own Secure Sockets Layer (SSL) certificate. If there is a problem with this certificate, the originating server may refuse the connection.
This may seem like a lot of potential causes to cover. However, most of these causes are fairly easy to rule out during the troubleshooting process, as we will see in the next section.
How to fix error 521 with WordPress and Cloudflare (3 methods)
Now that we’ve covered the basics, we’ll explain how to resolve Cloudflare error 521 in WordPress. We’ll go step by step, eliminating the most common (and easiest to fix) causes first. Let’s start by checking if your website’s server is down.
1. Check if your website server is down
Server downtime is quite rare with reputable web hosting providers. Many providers boast of near perfect uptime. So, unless you are using an unreliable web host, you can probably rule out this as the cause of the 521 error.
However, it’s always a good idea to make sure that this isn’t the problem, especially if you’re new to your current host. If you can’t access your website due to the 521 error, there are other ways to check if it is online. For example, you can use the ping command in the command terminal, which should work regardless of the operating system (OS) you are using.
The ping command performs a simple test to determine if a server is reachable and to make sure you don’t have connectivity problems. For example, here we run a simple ping test for Google.com (by typing “ping google.com”):
If you get a response from the server, it is up and running and reachable.
Another way to check if the server is down is to use a free online service such as IsItDownRightNow? This tool allows you to enter the URL of your choice and check if it is accessible:
If the service says the website is online, all is well. This means that the cause of your 521 error is elsewhere. If your server is down for any reason, you should contact your hosting provider to find out why.
2. Configure your server’s firewall to whitelist Cloudflare’s IP address ranges
The next solution you can try is to make sure your server’s firewall knows to let Cloudflare requests through. Depending on the type of hosting plan you use, you may not be able to change your server configuration manually. On most shared and managed plans, for example, you won’t be able to change the server’s firewall settings.
If you are using an unmanaged virtual private server (VPS) or dedicated server, you should have full access to the necessary options. If you are using a firewall, you can change its settings and whitelist Cloudflare’s IP ranges.
You can also contact your hosting company and ask them to check if the server’s firewall is blocking any of Cloudflare’s addresses. Due to the popularity of the CDN, this should not be the case. However, your host’s support team will be able to give you a definitive answer.
3. Setting up a Cloudflare Origin Certificate
Cloudflare allows you to configure how the CDN should handle SSL certificates. It gives you several options for SSL modes, including:
-
- Flexible
- Flexible
With this mode, Cloudflare will connect to your website using HTTP. Ideally, you should not use this mode unless you have not yet configured an SSL certificate for your website.
-
- Complete
This mode allows users to decide whether to use HTTP or HTTPS to connect to your website. However, if they use HTTPS, Cloudflare will not validate your website’s certificate.
- Strict
This mode also allows visitors to decide which protocol to use. However, it tells Cloudflare to check the validity of your website’s certificate.
If there is a problem with your certificate that is causing the 521 error, this usually occurs when you use Strict SSL mode. This is because Cloudflare also needs an original certificate on its side to encrypt traffic with your website.
Generating a Cloudflare origin certificate is simple, and once you do, you should be able to access your website without the 521 error. If there is a problem with your site’s certificate, you will see a different error code (error 526).
Conclusion
If you are using Cloudflare with WordPress, you are likely to encounter error 521. This particular error code appears when Cloudflare fails to establish a connection with your website’s server. This may be because the server is down, its firewall is blocking Cloudflare, or there is a problem with its SSL certificate.
To recap, here’s what you can do to resolve the 521 error in Cloudflare:
- Check if your site’s server is down.
- Configure your server’s firewall to whitelist Cloudflare’s IP address ranges.
- Configure a Cloudflare origin certificate.
Have questions about troubleshooting the 521 error in Cloudflare? Let’s talk about it in the comments section below!