Jan 14, 2022
Cloudflare Error 522: 3 Confirmed Methods to Fix It
The Error 522: Connection timed out message is a server-side issue common for websites using Cloudflare. In this article, we’ll find out what causes the error 522 and how to fix it.
Make sure you have access as a server administrator since it is a server error as the only other option is to contact the website’s owner. However, if you have access to the origin server, continue reading to learn three methods to fix this issue.
We will also share how to troubleshoot other related issues in order to avoid experiencing any other Cloudflare errors.
What Causes the Cloudflare Error 522?
The Error 522: Connection timed out message is an HTTP status code. A content delivery network (CDN) service, like Cloudflare, speeds up the network connection between a browser user and a website’s origin server. However, sometimes the server fails to respond within a specified time.
This issue also means that the Transmission Control Protocol (TCP) handshake between the web server and Cloudflare has failed. The TCP handshake is essential to establish a connection whenever this CDN service receives a user request.
So, why does the origin server not respond in time? Here are some of the most common reasons behind connection timeouts:
- Server overload. When an origin server faces too many requests, it cannot respond in time.
- Firewall blocks Cloudflare requests. Some web hosting providers have firewall features that might block Cloudflare IP addresses, which flags requests from the CDN.
- Incorrect IP address. The addresses on your domain name system (DNS) do not match with the ones on Cloudflare.
- KeepAlive disabled. Cloudflare activates KeepAlive messages by default. If they are disabled, the connection setup fails.
Any of these cases can result in the error 522 on your website. Most browsers will show the same image and message, indicating that the problem lies on the web host.
Note that this error is not caused by any Cloudflare malfunctions. Furthermore, this issue can happen no matter if you use a premium or a free version.
Here is the summary of this Cloudflare error 522:
|Error type||Server error|
|Error variation||Connection timed out|
|Error causes||The server has reached the maximum limit|
Firewall has blocked a Cloudflare IP address
Incorrect IP address
3 Steps to Fix the Error 522: Connection Timed Out
With each step to fix the Error 522: Connection timed out issue, we will also share how to check the specific cause behind your error.
1. Check if the Web Server Is Working
A common cause behind the Cloudflare error 522 is that a web server cannot handle HTTP requests as it is already overwhelmed. This issue often happens with shared hosting servers. To troubleshoot this error message, check if the origin web server is active and accepting HTTP requests.
There are different ways to check your site’s origin web server, including using the Packet Internet Groper (PING) command for Linux or Traceroute for Windows. Both Linux and Windows use a PING command to check the connectivity status of your website’s server.
Another reason your origin server is not working might be the high load of requests to your website. So, check your order usage to avoid hitting any limits. Each hosting provider will have its own way of accessing this information.
For Hostinger users, head to hPanel -> Order Usage and take a look at the:
- CPU usage – refers to the Central Processing Unit (CPU) consumption. Keep it under 80% to avoid poor performance.
- Memory limit – the amount of memory that the account processes.
- Processes – the total number of all processes in the account.
- Bandwidth – the amount of data transmitted in a fixed amount of time.
Reaching the maximum threshold for any of these metrics will slow down the website and cause this error. To determine whether you have reached the limit, check if the purple line touches the red line on the graphs.
Here are some ways to improve performance and optimize server capacity:
- Fewer plugins. Some plugins create more queries than necessary to the corresponding database, generating a high load on the origin server. Remove unnecessary plugins to avoid using too many server resources.
- Revise code. Poorly optimized code can cause high CPU usage. If you’re comfortable with editing the website’s code, consider revising it for faster performance.
- Upgrade or change the hosting plan. When you are close to reaching the memory limit, upgrade your web host plan or switch to a different type of web hosting.
In addition, check if there is ongoing maintenance, and if so, just wait until the maintenance is over and the speed returns to normal.
We recommend checking order usage regularly to prevent the Cloudflare error 522 from happening.
2. Review Cloudflare DNS Settings
Cloudflare will import all DNS records when integrating into a domain. One of the records is the Address Record (A Record), responsible for connecting the domain with the IP address of the origin web server.
Therefore, an IP address mismatch can cause the Error 522: Connection timed out message. The A Records on the hosting server and Cloudflare have to match to avoid this issue. Open the DNS Zone Editor and check the A Records to fix this issue.
For Hostinger users, access the DNS Zone Editor under hPanel. On the DNS settings, take note of the IP address under Content, next to Type A.
Next, head to your Cloudflare Configuration Menu and click on the DNS button. Under it, check the IP address next to Type A. Make sure the IP addresses are the same on both DNS servers.
If the A records are different, change them on Cloudflare’s DNS settings. Click on the Add Record button and insert the host server’s IP address into the IPv4 address box. Click on the Save button to process the changes.
This action should fix the Error 522: Connection timed out issue. Note that DNS updates can take up to 24 hours to propagate. However, purging the Cloudflare cache can make the process faster.
Another DNS setting to double-check is the Cloudflare encryption modes. We recommend setting the encryption mode to Full to prevent this issue from happening again.
3. Look Through Other Web Server Settings
Another solution to fix this is to check the website’s server settings. In particular, take a look at these three:
Cloudflare uses the KeepAlive header entry to maintain established connections with the web server. KeepAlive is an instruction that keeps the TCP connection with HTTP requests to remain open.
Disabling the KeepAlive message header in the origin web server causes the error 522 due to connection failure. As such, always enable the KeepAlive header to reduce the server’s CPU and memory usage. To employ this method, make sure to have access to one of the following files:
- .htaccess – hypertext access helps configure additional features for websites on the Apache web server. Hostinger users can find this file inside the File Manager.
- nginx.conf – the main configuration file of NGINX, the open-source web server software.
To demonstrate how to enable the KeepAlive header, add the following code to the .htaccess file:
<ifModule mod_headers.c> Header set Connection keep-alive </ifModule>
Allow Cloudflare IPs
Another reason behind the 522 HTTP error is a firewall feature that blocks Cloudflare’s IP addresses – make sure to check IP filtering on your host provider to allow requests from Cloudflare IPs.
Hostinger has an IP Manager to grant access or block specific web addresses. Head to hPanel -> Other -> IP Manager to control IP routing for your site. Include Cloudflare IPs under the Allow an IP Address section and click Add.
If your control panel does not have an IP manager, use the .htaccess file inside the File Manager. Add the code allow from and insert Cloudflare’s IP addresses between the lines:
#DO NOT REMOVE THIS LINE
The code will look like the image below.
These changes will allow the server to accept Cloudflare requests and should fix the error message.
If none of the previous methods work, disable this CDN service temporarily. Every web hosting provider has their own way to do so. Hostinger users with Cloudflare can follow these steps:
- Head to your hPanel and click on Cloudflare under Domains.
- Toggle the Service status off and click the Save button.
To use the CDN again, we recommend restarting your Cloudflare account.
Troubleshooting Other Cloudflare Errors
There are other HTTP status messages that Cloudflare users might receive. For example, Error 520: Web server is returning an unknown error. This issue’s common causes are a crash at the origin web server or Cloudflare incompatible response header.
The troubleshooting steps for Error 520 include:
- Ensure Cloudflare DNS records are correct.
- Disable your .htaccess file.
- Check headers and cookies.
Another possible issue is Error 521: Web server is down, often due to poor Cloudflare encryption settings or inaccessible server. Here are some of the ways to troubleshoot Error 521:
- Ensure the origin server is running.
- Test the connection to the server.
- Check encryption settings.
We advise you to contact Cloudflare support services if these issues persist.
The Cloudflare error 522 happens when a server takes longer than the specified time to respond to requests. Some of the common reasons behind this issue are insufficient memory or CPU, your firewall blocking an IP address, and a disabled KeepAlive header.
Let’s recap the three methods to fix this issue:
- Check your connection and memory.
- Review Cloudflare DNS settings.
- Configure your server settings.
Let us know in the comment section below which method works best for you.