Cloudflare Error 522: 3 Confirmed Methods to Fix It

Cloudflare Error 522: 3 Confirmed Methods to Fix It

Error 522 is an HTTP status code that indicates a connection issue where the origin server doesn’t reply, often seen with CDN services like Cloudflare. It happens when Cloudflare can’t get a response from your site within the expected timeframe.

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.

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.

Error 522 on a web browser.

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 codeError 522
Error typeServer error
Error variationConnection timed out
Error causesThe server has reached the maximum limit
Firewall has blocked a Cloudflare IP address
Incorrect IP address
KeepAlive disabled

How to Fix the Error 522 – Video Tutorial

Watch our video tutorial on how to fix Error 522.

Subscribe For more educational videos! Hostinger Academy

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.

Important! First, check if the website is down for everyone and ensure that Cloudflare system status is working properly before proceeding with the steps. Use a tool like uptrends to do so.

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.

The Resources Usage page on hPanel

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.

Pro Tip

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 hPanelAdvanced. On the DNS settings, take note of the IP address under Content, next to Type A.

DNZ Zone Editor on hPanel with the IP addresses highlighted

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.

DNS button on Cloudflare's menu.

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.

DNS records on Cloudflare.

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:

Enable KeepAlive

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:

  • .htaccesshypertext 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.

The IP Manager button on hPanel

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.

Lines of code on htaccess.

These changes will allow the server to accept Cloudflare requests and should fix the error message.

Disable Cloudflare

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.

Hostinger web hosting banner

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.

Additionally, the 504 error occurs when Cloudflare is unable to receive a timely response from your origin server. Troubleshooting steps for a 504 error are:

  • Checking if the upstream server is overloaded or down.
  • Reviewing network configurations and connectivity between servers.
  • Verifying timeout settings on your server and proxy.

We advise you to contact Cloudflare support services if these issues persist.

Conclusion

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.

Author
The author

Astari S.

Astari is a digital marketing expert, with a focus on SEO and WordPress. She loves to share her wealth of knowledge through her writing, and enjoys surfing the internet for new information when she's not out in the waves or hiking a mountain. Her mission is to learn something new every day, and she firmly believes that there is no such thing as too much knowledge.