How to Fix 504 Gateway Timeout Error in WordPress?

504 gateway timeout error
By

0 Comment

9 mins Read

504 gateway timeout error
Get your SSD VPS

Get your SSD VPS

Starting from $4.95/month.

Check it Out

504 gateway timeout error is an HTTP status code, a type of report code that a server sends back in answer to an incoming request when it has been unable to complete a request. You surely have encountered this error before while browsing, although this one is not as common as other 5xx series errors such as β€œ500 internal server error” or β€œ502 bad gateway error.” In this guide, we explain what this error means and how you can fix it in WordPress.

When a user visits your website, they generate and send HTTP requests to your WordPress web server that runs your website. For each received request, your server sends back an HTTP status code with the requested resources from your website. The user does not usually see this unless something fails to work, and then they will see an error code, an HTTP status code that gives a hint as to what did go wrong.

Start Blogging Start Blogging

Self-host your WordPress on top-tier hardware, featuring NVMe storage and minimal latency around the world β€” choose your favorite distro.

Get WordPress VPS

What is 504 Gateway Timeout Error?

This is a 5xx series status code. The β€œ5” series are server-side errors, which means the problem is for the administrator to solve. There are about a handful of error codes, and each has different solutions (for example, see our quick-fix guide to HTTP error 505). As you may know, an error may happen anywhere along with the connection, in the user’s browser, in their internet connection, anywhere on the way between, or at your server. When it happens outside the scope of the user, it is a server-side error. It appears when a request fails to complete because of miscommunication between several servers.

There are several ways that this error may appear to the user (or to you, when you are browsing the internet.) For instance:

  • 504 Gateway Timeout
  • 504 Gateway Timeout nginx
  • Gateway Timeout Error
  • HTTP Error 504
  • 504 Gateway Time-out – The server didn’t respond in time
  • This page isn’t working β€” Domain took too long to respond
  • HTTP Error 504 – Gateway Timeout
  • Gateway Timeout (504)
  • HTTP 504
  • 504 Error

But what does it mean?

What Causes 504 Error?

504 Gateway Timeout error is shown when a server does not receive a timely response from another server that acts as a gateway or proxy between your user and your website. Simply put, means that a request was sent to your website, but the time ran out of waiting for a response.

Some of the most common causes for this error are connectivity problems:

  • Poor internet connection on the user’s side, leading to miscommunication and therefore not receiving an answer.
  • Browser compatibility issues, once again causing miscommunication and timing out on a response.
  • Improper proxy settings, which basically block the request from reaching the server, therefore not receiving an answer.

However, it is possible that there is actually a problem on the server’s side. If you are using a weak device or server for hosting your WordPress website, your server might run out of resources to answer requests in time, especially in peak traffic. This causes slow web performance leading to timing out on responses.

In a similar case, if you are using a shared hosting plan, it is enough for only one or two of the websites hosted on the shared server to hit peak traffic to slow down every single website running on that server. The reason for that is, as the name suggests, on shared hosting all the resources are shared among all the clients at the same time. That is unlike VPS where you get dedicated resources all to yourself. That is actually the biggest reason for opting out for WordPress VPS rather than shared hosting.

504 gateway timeout error can also happen when there is a mistake in firewall configuration on your server. This happens a lot, especially when using a Content Delivery Network or CDN for serving your content faster to the user. A CDN is a network of proxy servers that stand between your web server and your user, and try to serve the most highly requested static data on your server to the user from a closer point in the network, thus reducing both their latency and the load on your web server. But your firewall may be blocking some of the requests that come through by means of that CDN network, like Cloudflare.

Another common cause of 504 error is DNS Error. If you configure your DNS settings incorrectly, or there is a mistake on the public DNS server concerning your website, users’ requests might not reach you because they are unable to find your server, thus a timeout error. This can also happen due to incorrect DNS settings on the user’s part, or their proxy server.

Start Blogging Start Blogging

Self-host your WordPress on top-tier hardware, featuring NVMe storage and minimal latency around the world β€” choose your favorite distro.

Get WordPress VPS

How to Fix 504 Gateway Timeout Error?

As we said before, although 504 is classified as a server-side error, there is a chance that some users encounter this error due to faults on their own side. What you can do when a 504 is reported on your website, is to try and trace the possible cause from user-side slowly to server-side.

Before getting into ways for fixing this error on your WordPress website, remember that some of these methods require making changes to your server files and server settings, so it is highly recommended to first make a proper backup of your website and anything that you might change.

1. Refresh or reload the page

Make sure there is actually a problem and it was not just a passing error. Sometimes the server is just overloaded for a moment, and refreshing the webpage will load it properly. Just wait a couple of minutes and then hit the refresh button, or press Ctrl+R (in Windows) or cmd+R (in Mac).

refresh button in browser

2. Try a different browser.

Sometimes the problem is from the specific browser you are using. Try a different one and see if the error persists.

3. Check different locations.

While waiting a couple of minutes to refresh the page, you can check to see if the issue is from your device or server-side, from the website. There are various services you can use to check on your website from different locations. You can test the website with Down for Everyone or Just me or Is it Down Right Now?

If the issue is user-side, there may be a problem with the user’s browser, internet settings, firewall, proxy, or connectivity. Sometimes restarting the device or the network devices solves the problem for the user.

4. Flush DNS

Sometimes 504 gateway timeout error can be due to an incorrect or outdated DNS cache, but clearing it is easy. Although, depending on your operating system, the way of doing it may differ.

To flush all DNS records on your system in Windows OS, open Command prompt (cmd), then enter the code below and hit the enter key for it to run:

ipconfig /flushdns

After the command is run, you should see a result line like in this picture:

flush dns windows

If you are using Mac OSX operating system, to flush your system’s DNS records open the terminal and enter the code below:

sudo killall -HUP mDNSResponder

If you are on a Linux system, you can open a terminal window and enter the code below:

sudo/etc/init.d/nscd restart

This is flushing the DNS on the user-side. If the problem is on the server-side the steps so far are unlikely to solve the issue. It is time to try and fix the problem on your WordPress server.

5. DNS Problems

If you have recently made changes to your DNS settings on your web server, there is a chance that those changes will take up to 24 hours to take effect everywhere on the internet. In the meanwhile, users trying to connect from certain networks will fail to find and connect to your website.

You can temporarily switch the DNS server to Google Public DNS to see if the HTTP status code appears as a result of a DNS problem. However, it is recommended for more advanced users.

Start Blogging Start Blogging

Self-host your WordPress on top-tier hardware, featuring NVMe storage and minimal latency around the world β€” choose your favorite distro.

Get WordPress VPS

6. Check Error Log

504 gateway timeout error may also occur as a result of recent website changes or updates. A quick way to find out is by checking the error log and see if you can find the culprit. In your WordPress website you can enable error message logging by adding these lines to the wp-config.php file:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Once done, all generated logs will be recorded in the wp-contents/debug.log file.

debug file filezilla

7. Check your Plugins.

It is common for a faulty plugin to be the cause of the 504 timeout error. Outdated or incompatible plugins and extensions can cause different problems and errors in WordPress. In this case, a plugin related to caching may be at fault. The problem is you don’t normally which one is the culprit.

To find if any of your WordPress plugins is causing the 504 gateway timeout error, you need to deactivate all your WordPress plugins and then reactivate them one by one to see which one can cause the 504 timeout issue.

Go to your WP admin dashboard, and click on the plugins tab. Here, check the box in front of β€œPlugins” to select all your plugins, then from the β€œbulk action” menu, select deactivate and click apply.

wp plugins bulk deactivate

If deactivating all your plugins solves the issue, then you know one of your plugins may have caused it. Start reactivating the plugins one by one and check if the issue returns after reactivating any of them. When you found the plugin at fault, disable or delete the plugin to solve the problem, and return the other plugins to their previous state.

8. Check your Content Delivery Network (CDN)

If you are using a CDN to deliver your website content faster, you need to check if all is ok on that side as well. Cloudflare is one the most commonly used CDN solutions for small to medium websites, acting both as a CDN and Cloud Security system mitigation DDoS attacks.

504 gateway timeout cloudflare

The above version of the 504 error appears when something has gone wrong on Cloudflare’s side. You could contact Cloudflare support or disable it entirely. If you opt for disabling it, the changes to DNS records may take a few hours to take effect.

However, it is more common to see the 504 error as shown below. This mode means that Cloudflare CDN cannot receive an answer from your web server.

cloudflare 504

9. Check Firewall Settings

Setting your firewall properly is very important in how your website works and answers requests. Especially when you are using a CDN to serve your content, since many requests come from the same CDN nodes, your firewall may flag it as unwanted traffic and block the requests.

To fix this, you will need to whitelist all IP addresses from your CDN on your website’s firewall system. Generally, you can find a list of the CDN’s IP addresses on their website.

You can whitelist an IP address in the .htaccess file on your server. Follow these steps in order to do that:

  1. Connect to your web server using an FTP client such as FileZilla, then move to the root directory containing your website’s files.
  2. Double-click the .htaccess file to download a backup of it.
  3. Then right-click on the .htaccess file on the server and select View/Edit.

504 htaccess edit

Now copy and paste the following bit of code into the file:

<RequireAny>
Require all granted
Require ip 127.0.0.1
</RequireAny>

Replace the 127.0.0.1 address with the IP address you wish to whitelist. For each of the IP addresses you want to whitelist, copy, and paste this one line under the previous one and then change the IP address to what you want.

10. Change Server Configurations

If you are using WordPress VPS hosting for your website, there are a couple of things you can try to fix the 504 gateway timeout error. They would involve tweaking some server settings and configurations and increasing specific resource limits. But as always, remember to first backup everything.

For this method, you need to have SSH access to your VPS. If the webserver running on your VPS is Apache, you can connect through SSH into httpd.conf file and increase the default timeout value. Add the following code to the file:

# Timeout: The number of seconds before receives and sends time out.

Timeout 600

Another popular web engine is Nginx. If you are using Nginx, you can edit the timeout.conf file located at /etc/nginx/conf.d/timeout.conf

Add the bit of code below to the file:

proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;

11. Upgrade your Hosting Plan

If you are running a successful WordPress website with increasing traffic, it is inevitable to run short on server resources at one point, which can lead to 504 timeout errors for users. It is recommended to upgrade your hosting plan in accordance with your website’s traffic.

Start Blogging Start Blogging

Self-host your WordPress on top-tier hardware, featuring NVMe storage and minimal latency around the world β€” choose your favorite distro.

Get WordPress VPS

Conclusion

504 Gateway Timeout error is a server-side error, but it basically means that the user cannot reach or receive an answer from the server, so this may be happening anywhere from the user’s browser and an internet connection to your own website server.

To find out and fix the problem, you need to check the issue step by step to see what solves the problem, and then make a fix to permanently solve the issue. If none of these steps solved the 504 error for your website, it’s best to contact the customer care of your hosting company and ask them for help.

A Web designer, with Experience in digital marketing , Totally fueled by passion to understand and learn different aspects of digital marketing.

Comments

Leave a Comment

Your email address will not be published. Required fields are marked *


Get your SSD VPS

Get your SSD VPS

Starting from $4.95/month.

Latest Posts