Sep 26, 2023
Cloudflare Error 522: 3 Confirmed Methods to Fix It
The Error 522: Connection timed out message is a common server-side issue for websites utilizing Cloudflare’s services. As this error originates from the server, solving this issue requires access as a server administrator.
In this comprehensive article, we will delve into the root causes behind the error 522 status code and discuss three effective solutions to resolve it promptly.
Beyond resolving this specific error, we will also share valuable insights on diagnosing and preventing potential Cloudflare errors, ensuring a smooth browsing experience for your website visitors.
Watch How to Fix Error 522
Watch our video tutorial on how to fix Error 522.
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 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 an error 522 status code on your website. Most browsers will show the same image and message, indicating that the problem lies with the web host.
Important! 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 → Hosting → Resource Usage and take a look at the following data:
- CPU usage – refers to the Central Processing Unit (CPU) consumption. Keep it under 80% to avoid poor performance.
- RAM usage – the amount of memory that the account processes.
- Processes – the total number of all processes in the account.
- Input and output – the speed of data transfer.
Reaching the maximum threshold for any of these metrics will slow down the website and cause this error. The donut charts give you insights into the number of resources used and available.
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 → Advanced. 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 → Advanced → 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.
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 an 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.
Troubleshooting Other Errors
Error 404: 4 Ways to Fix It
How to Fix 502 Bad Gateway Error
How to Solve 503 Service Unavailable Error
How to Fix 504 Gateway Timeout Error
Localhost Refused to Connect Error
How to Fix PR_END_OF_FILE_ERROR
How to Fix cURL Error 28
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.
Remember that a server administrator access is required to solve this issue. Let’s recap the three methods to fix this issue:
- Check your server connection and memory. Make sure that the server can handle the requests.
- Review Cloudflare DNS settings. Make sure you have the right IP addresses for the DNS settings.
- Configure your server settings. Enable KeepAlive and allow Cloudflare IPs in your server’s settings.
Let us know in the comment section below which method works best for you.
Error 522 FAQs
Here are some frequently asked questions about error 522.
What Are the Common Causes of Error 522?
Error 522 usually occurs due to a connection timeout between the web server and the Cloudflare proxy. The common causes include server downtime, issues with the web server, firewall or security plugin misconfiguration, heavy traffic, and problems with the hosting provider’s network infrastructure.
How Do I Know if Error 522 Has Been Fixed?
Check if the website is loading properly and if you are able to access it without any issues to confirm that error 522 has been fixed. Additionally, you can use online tools or services that can perform uptime monitoring to ensure it is up and running without any errors.