Error 522 is a server-side error that occurs on websites which are using the CDN services of Cloudflare. It is not an uncommon error, however fixing it can be a hassle at times. This is the most exhaustive guide you’ll find on the internet to fixing Cloudflare Error 522: Connection Timed Out.
The steps to fix Cloudflare Error 522 may vary depending on what is causing the issue. The basic solutions include checking your web server usage and DNS settings, enabling TCP keepalive, and making sure Cloudflare IPs are allowed. We have explained each of these methods in detail later in the article.
Please know that you cannot fix the error 522 if you are simply a visitor to the website. It is an issue from the server-side, and not the client side. It can only be fixed if you have admin access to the website.
This is what the error looks like:
A little bit about Cloudflare
Cloudflare is a widely used content delivery network or CDN for short.
It is extremely famous and extremely useful. It offers various features such as CDN, caching, DNS management, rocket-loading, image optimization, and a lot more.
As of today, Cloudflare has over 4.1 million total users out of which a whopping 119,206 pay for the service. Simply put, it’s a huge company.
One of the most common uses of Cloudflare is as a reverse proxy server. It adds much needed protection to your website.
Cloudflare has both a free version (which offers simple features such as CDN, DNS management) and paid versions with a lot of extra features.
However, please note that the Cloudflare error 522 can occur on both free as well as paid versions.
What does a 522 error mean?
522 is an HTTP error code. The HTTP error 522: Connection timed out is an indication that the server (on which the website is hosted) failed to send back data within a specified time limit.
That is why it says, “connection timed out”. The server couldn’t respond fast enough.
Now, this error can occur regardless of whether you are using Cloudflare or not, but it is mostly only seen on websites which are using Cloudflare.
That is why this article is mainly focused on the Cloudflare error 522.
The HTTP error 522 also means that the Transmission Control Protocol handshake was unsuccessful between the server and the Cloudflare.
We don’t want to make it too technical, but what is TCP (Transmission Control Protocol)?
It is simply a way for servers, applications, and computing devices to talk to each other over a network.
When TCP fails, Cloudflare can’t talk to the origin server. That’s bad news.
By the way, “origin server” is basically the main server on which your website is hosted. The CDN servers that Cloudflare uses to serve your content to your users are referred to as Edge servers.
What causes the Cloudflare 522 error?
Cloudflare error 522 can have many causes, and here is an exhaustive list of those causes.
- Overloaded origin server – This is one of the main causes of Cloudflare error 522. If your origin server is overloaded beyond its capacity, it won’t be able to respond in time, hence giving the error code 522: connection timed out.
Server overloads occur because too many people open the website at the same time. This, in technical terms, is usually referred to as a server getting too many requests which it is unable to handle. - Cloudflare IP adresses are blocked or rate limited – According to Cloudflare’s official website, this is the most common reason for HTTP error 522. Rate limiting basically means that Cloudflare IPs are getting blocked after a certain number of requests. It is a complex topic, so let’s not get too technical.
You may have mistakenly rate limited or blocked the Cloudflare IPs via your. htaccess, firewalls or iptables. That will result in HTTP error code 522. - You have TCP keepalives disabled – TCP keepalive has basically one purpose – keep TCP alive. If keepalives are disabled on your origin server, you will see Cloudflare error 522: Connection timed out. If you want to know more, you can check out this detailed article on TCP keepalives.
- Wrong DNS records – This is a rookie mistake, but if you simply have put the wrong IP address as your A record, then you will experience this error. You should make sure that all of your DNS records are correct.
- Packets not getting exchanged properly – Any data that is sent over the internet is sent in small collections called packets. Cloudflare states that error 522: connection timed out can occur when packets are being dropped at your origin server (i.e. not being recieved properly).
- Firewall is blocking Cloudflare’s requests – All web servers have firewalls and they are one of the most important aspects of security. Different hosting providers use different firewalls which have different features. It is a possibility that your hosting provider’s firewall may be blocking Cloudflare’s IP adresses, in which case you’ll get error 522.
- Origin server is simply offline – This is least likely cause because usually Cloudflare will display a different error code when the web server is offline. However, in some cases, Cloudflare may display error 522 as well (because it is taking far too long to exchange packets with the server…. which is infact an impossible task, since the server itself is offline.)
That’s a lot of causes for error 522 and it may be overwhelming. But please rest assured – we will first help you pinpoint what is causing the issue, and then go on to tell you how to fix the Cloudflare Error 522: Connection Timed Out on your website.
You will not lose any more traffic, we assure you.
Fixing Cloudflare Error 522: Connection Timed Out
Before anything else, make sure about these two things:
- That the origin server is not down. There will probably be a page on your host’s website which will show if their server is currently online or offline. Check that, or simply ask the support.
- Make sure that the website is down for everybody, and not just you. Open your website from a few different networks or ask other people to open it to make sure that everyone is seeing error 522.
If both of the points above stand correct, then the error indeed is server-side and can be fixed through the means that we are going to share here.
Here are some tested methods to fix Error 522: Connection Timed Out in Cloudflare, one of these will certainly work for you.
Method 1: Make sure that the web server is working well
As we have already said before, the first thing that you should do is make sure that your web server is online and working fine.
Most web hosting companies have a live status report for their servers where they show if the servers are online or offline (for maintenance, or because of some issue).
If your hosting company does not have such a feature, at the very least, I’m sure they would send you a mail if the servers were going down for maintenance or some other reason. Check your email.
If the web server is online, you need to make sure that it’s not overloaded.
How to figure out if your server is overloaded?
Whether you are using cPanel, Cyberpanel, hpanel, Plesk or anything else, they all have a “usage” page where they show statistics such as:
- Current CPU usage – It should be below 70-80% in most cases. If your CPU usage is above that, you need to talk to your hosting provider and upgrade your plan. That will fix error 522 for you.
- Disk Usage – This is usually not the cause of error 522, but you should make sure that your disk space is not full any ways.
- Ram Usage – It is important for your ram usage to be below 70-80% as well. If it is above that, upgrading your plan is the only way fix Cloudflare error 522.
- Bandwidth – If you’ve recently had a bump in your traffic, your current plan’s bandwidth might be unable to keep up. This can aggresively result in error 522 and the only solution is to increase your bandwidth.
It is a good practice to stay updated with all of these metrics because any of them nearing their maximum value can cause your website to crash, malfunction, or show errors.
If upgrading your plan is not an option, here are some ways to reduce your server usage in the same plan:
- Use less number of plugins – If you are on a CMS such as WordPress, plugins can heavily affect your website performance as well as your server’s capabilities. It is always advisable to use as few plugins as you can. If removing a plugin is not an option, try to look for alternate, more light-weight options for the same job.
- Delete all unused images, themes, files – This can help clear your disk space and improve your server’s performance. Besides, as an OCD guy, I like to do regular checks to get rid of unused things.
- Use a more lightweight theme – If you are on WordPress, lightweight and well-coded themes such as Generatepress, Astra, Blocksy can increase your website’s speed, reduce your server load and the number of requests it makes. If you have a custom-coded website, it is important to make sure that the code is well-optimized.
Method 2: Enable Keepalive on your website
Like we said before, the main purpose of keep-alive is to keep the TCP of your web server or your origin server working. Cloudflare has a very important use for keep-alive. It uses TCP keep-alive to maintain its connection with the web server.
if the keepalive is disabled, Cloudflare will no longer be able to exchange data with the server and you are bound to experience HTTP error 522.
Keeping keep-alive enabled will not only prevent Cloudflare error 522 from occurring, but it will also reduce your server’s load such as CPU usage, ram usage.
Here is how to enable the TCP keepalive header (or simply, keepalive):
- If you are on an Apache web server, open your .htaccess file or create one if you don’t have it already. Inside the file, add the code below:
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
- If you are on an NGINX server, you will have to add the code above to nginx.conf, which is the main configuration file of NGINX web server.
Interesting Fact: Did you know that the full form of .htaccess was hypertext access?
Method 3: Allow Cloudflare IPs
If enabling keepalive didn’t work, maybe the Cloudflare IPs themselves are getting blocked? This is BOUND to result in HTTP 522 error: connection timed out.
Luckily, it is not very difficult to fix.
The specific steps for this will depend depending on what host you are on, but you know… the simplest way is to just contact your host.
Contact your host and ask them to enable the Cloudflare IP. If your support is not very responsive, you can do it manually as well.
Some hosts have an IP manager and you can simply allow the Cloudflare IPs from there. You can find your Cloudflare IPs within your Cloudflare account.
If your host does not have an IP manager, you will have to edit the .htaccess file again. Open your .htaccess file, and add the code below:
allow from 123.123.123.123
This is supposed to be added within the #DO NOT REMOVE THIS LINE part inside your .htaccess. If you are unsure of how to go about this, I think it will be best to just contact your support because wrongly editing your htaccess can be costly.
Method 4: Make sure Cloudflare DNS settings are okay
This is pretty basic. Whenever you set up any website, you set up some DNS records to make sure the domain is pointing to your server. In some cases, the DNS records are set up automatically and all you have to manually do is update the nameservers.
However, you may experience error 522 if you have set up your DNS records incorrectly within Cloudflare.
Within your Cloudflare DNS settings, there are two records that you MUST have:
- An “A” record that has host set to “@” and value set to your server’s IP address.
- A “CNAME” record that host set to “www” and value set to “domain.com”.
If you have both of these records entered correctly, and are still experiencing the error, you might want to delete all the other records (except these two) and try visiting your website. That might fix HTTP error 522.
Method 5: Temporarily disable Cloudflare
If all four of the methods above have failed to fix Cloudflare error 522: connection timed out for you, then maybe disabling Cloudflare itself is a good idea.
You can pause Cloudflare from the Cloudflare homepage with one click. If this fixes the error, then there must be something within your Cloudflare settings that is causing error 522.
You’ll have to troubleshoot and figure out which one of the Cloudflare settings is causing the issue… although that can be really exhausting. I understand. In that case, simply follow method 6.
Method 6: Contact Cloudflare support
If none of the above work, then unfortunately you’ll have no choice but to contact Cloudflare support.
Luckily, Cloudflare has a very responsive support system and they are fairly technical as well.
They will certainly assist you in pinpointing what is causing error 522 (connection timed out) and how to fix it.
Fixing Cloudflare Error 522 on WordPress is the same as fixing it on any other website. The CMS is not relevant here.
Whether you have a manually coded website, or a WordPress website or a website hosted on some other CMS, the steps to fix error 522 remain same.
This article is an EXHAUSTIVE guide to fixing error 522 within this article. We have mentioned 6 methods, and one of them is bound to work for WordPress as well.
No, error 522 is in no way a virus. It is an HTTP status code which indicates that the server was unable to respond in time. Hence its name, “Error 522: Connection timed out”.
This is a funny question, but apparently it is asked by people. Cloudflare error 522 is NOT caused by a virus, in almost all cases.
There is only one specific case that I can imagine in which it would be a virus issue. If a virus within your website’s server is eating your server’s resources and causing it to overload, then Cloudflare error 522 may occur.
But error 522 can never occur due to a virus on the user’s device.
Conclusion
This was the most exhaustive guide that we could have written on fixing Cloudflare Error 522: Connection timed out.
We gave it our all, really. As someone that runs websites and uses Cloudflare on most of those websites, I have had personal encounters with this error in the past and I understand how annoying it can be.
Let us know in the comments what method worked for you, and what else we can help you with. You can also talk to us for guest posts (or just to chit-chat) from our contact page. Have a nice day!