504 Gateway Timeout

How to Fix 504 Gateway Timeout

504 Gateway Timeout

One of the most common errors that occur on a web application is the 504 gateway timeout error. 504 error is one of many HTTP response status codes in the 5xx range that prevents the server from getting data from the database.

Like most server errors, the 504 gateway error does not give details as to why the gateway timed out, thereby making it difficult to pinpoint the cause of the error.

Also, a gateway timeout error can negatively impact your WordPress sites’ SEO. For this reason, it is important to debug and fix the error as soon as you start seeing it.

In this guide, we will share a couple of ways to troubleshoot and fix this error on your WordPress site. But first, let us understand the error and the common reasons why it occurs.

Content:

  1. What does 504 Gateway Timeout mean?
  2. Common causes of the error.
  3. How to fix 504 gateway timeout WordPress error
  4. Conclusion

What does 504 Gateway Timeout Mean?

504 gateway timeout is a server-side error that occurs when the server is taking a long time to load a web page.

This error occurs when 2 servers are involved in processing a request, and one server (the gateway server) times out while waiting for a response from the other (the upstream server). This means the gateway or proxy failed to receive a timely response from another server regarded as the upstream server.

The gateway is usually a server on a device (e.g. Wifi router) around you that allows you to access the internet. While the upstream server is the web host.

SEO Implications

When search engines such as google detect an error 504 timeout issue on your website, they interpret the error as an unavailable site. This may lead to search engines deindexing your page, thereby reducing your site ranking.

Also, when a user visits a site and is served the 504 bad gateway error page, it sometimes discourages the user and forces them to try out other sites with hopes to solve their query.

Variations of 504 gateway timeout

Depending on the operating system, web server, or browser, gateway errors can be presented in different formats. However, they are all referring to the gateway timeout error irrespective of the format the HTTP (Hypertext Transfer Protocol) status code is presented.

Website owners have the liberty to format how their 504 gateway timeout error is displayed. Below is a list of commonly used terms;

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

Common Causes of Gateway Timeout Error 504

The most common cause of this error is device-specific which occurs due to poor internet connection, browser compatibility issues or improper proxy settings from your PC.

Also, it can occur due to slow web server performance. If your WordPress site is using a shared hosting plan, then large requests from different sites may overload the server, leading to timeouts occurring.

504 gateway timeout can also occur if there is a faulty firewall configuration on the server. This happens when you are serving your site through a content delivery network (CDN) such as Cloudflare.

Another common cause is DNS Errors. An incorrect configuration in the public dns servers can result in the error 504 timeout page. In addition, the DNS errors can be caused by the user’ device and proxy server.

How to Fix 504 Gateway Timeout WordPress Error

The 504 error sometimes occurs due to faults from user devices. For this reason, it is important to troubleshoot user-centered causes and walk your way up to server-side causes.

Some of the fixes explained would require making changes to your site files on the host server, it is important to always back up your site before changing any file.

After backing up your site, proceed with the steps below.

Reload the web Page

As easy as this may sound, it might fix the issue. Sometimes, the webserver may be overloaded from multiple websites on the origin server.

Simply wait a few minutes then reload the page. To reload a web page, use Ctrl+R (in Windows) or cmd+R (in Mac). Alternatively, click on the reload icon at the top left side of the browser.

How to reload the webpage 1

While you are waiting for the page to load, you may also check if the issue is from your device or a general server problem from the website. For this, you can use Down for Everyone or Just me or Is it Down Right Now? To test the website for downtime.

If the issue is from the website, then you can try contacting the website owner or wait for them to resolve the issue. If you are the site owner, then you may proceed to try out some of the server-side fixes that will be discussed below.

checking the status of a website

However, if the site is working properly ( as seen in the screenshot below), then the connectivity issues may have been caused by your networking equipment. To resolve this, you can try restarting your network devices.

Checking the status of a website
 

Restart your System and Network Devices

Sometimes the fault can be from your home network or devices such as routers, repeaters, or modem. An easy fix is to restart your devices.

The devices can be turned off in any order, but the order in which they are turned back on matters. Typically, turning them on from the ‘outside-in’ is recommended, i.e. devices from your Internet Service Provider before system devices.

Flush DNS – Fix 504 Gateway Timeout

Using an incorrect or outdated DNS cache can result in the 504 gateway timeout WordPress error. To resolve this, you need to flush all system DNS records. Although it is relatively easy to flush DNS, the procedure differs depending on your operating system.

To flush DNS on Windows Operating System, Open Command prompt (cmd).

Now, paste the code below and then hit the enter key to effect the change.

ipconfig /flushdns

You should get a result similar to the code below.

Command prompt

For Mac OSX operating systems, you can flush DNS with the steps below.

Open terminal and then paste the code below.

sudo killall -HUP mDNSResponder

If you are on a Linux environment, then open a terminal window and paste the code below

sudo/etc/init.d/nscd restart

The DNS issues can also occur from the server-side. It occurs when you recently changed your DNS records. In this case, all you have to do is wait for the DNS to propagate properly which takes up to 24 hours in some cases.

Test with a Different Device

If the issue is device-specific, try loading the website from another device, or on another network. You may even try it on your phone to ascertain the root cause of the issue.

If it is still not accessible, then the error is likely from the server.

Deactivate Plugins

Installing a new plugin or updating older plugins can also tamper with your site configurations, leading to the error 504. Deactivating plugins can fix the error in some cases.

If you can access your WordPress site admin dashboard, click on the plugins tab.

Now, tick the box to select all plugins as seen below.

Deactivating all plugins - fix 504 gateway timeout

Then, click on bulk action, a dropdown will appear, select Deactivate and then click on Apply to deactivate all plugins.

Deactivating all plugins step 2

If this fixes the error for your website, great job. Begin activating all plugins one at a time, once you identify the faulty plugin (the plugin you activated before the error occurs again), delete permanently from your site.

However, if the error is preventing you from accessing your WordPress site admin dashboard, then you can disable the plugins via FTP.

Please read this guide to learn how to disable all plugins using FTP.

Check your Content Delivery Network (CDN)

If you are serving your site through a CDN, it sometimes runs into a 504 timeout error if the requests on the CDN’s servers are much or due to an improper server configuration.

One of the most common content delivery networks is Cloudflare. Luckily, Cloudflare can help specify whether the error is from their servers or your host server.

A Cloudflare specific error screen is similar to the one in the image below. If this is the error page you are seeing on your website, then it is most likely a Cloudflare specific error, which their engineers might be working on already.

Check CDN - fix gateway timeout error

A temporal fix for this error would be to change your DNS server settings and then deactivate the CDN completely from your site while they are still working on it from their end.

Another version of this error occurs when the issue is from your host server. The error page is similar to the one shown in the image below.

When the issue is from your host server

At this point, you could opt to notify your hosting provider or check your server’s firewall configuration.

Check Firewall Settings

If you are serving your site through a content delivery network, your WordPress host server sometimes flags large requests from the CDN, which can lead to an error 504 gateway timeout.

To fix this, you will need to whitelist all IP addresses from the CDN your site is using. For cloudflare users, here’s a list of cloudflare ip ranges.

You can whitelist an IP address in the .htaccess file on your host server. To do this, follow the steps below;

Connect your site to an FTP client, then navigate to the root directory containing your website’s files.

Now, double click on the .htaccess file to download a backup of the file.

After that, right click on the .htaccess file and select View/Edit.

View/edit .htaccess

Now, paste the following code snippet on the file.

<RequireAny>

Require all granted

Require ip 127.0.0.1

</RequireAny>

Replace 127.0.0.1 with the IP address you wish to whitelist.

To whitelist multiple IP addresses, enter a new line and then add the Require ip 127.0.0.1 command and replace with the correct IP. Repeat this until all IPs are whitelisted.

Change Server Configurations

This step works if you are using VPS hosting and have SSH access. If you are on a shared hosting plan, then simply reach out to your hosting providers for further guidance.

If your VPS hosting utilizes Apache, then you can SSH into the httpd.conf file and increase the default timeout value. Add the code below to the file to increase the timeout.

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

Another popular VPS platform is Nginx. If your VPS uses Nginx, then you can edit the timeout.conf file located at /etc/nginx/conf.d/timeout.conf

Add the following code to the file.

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

Check Error Logs – Fix 504 Gateway Timeout

Log files help debug errors that occur on a website. They provide details as to what went wrong on a site with reasons for the error.

By default, WordPress logs are turned off in the wp-config file. Turning it on is fairly easy.

You will need to access your WordPress site files via an FTP client or through cPanel. For this guide, we will be using FileZilla FTP client. Here’s a detailed guide on how to use FTP.

How to Check Error Logs

Firstly, connect your site to an FTP client. On the right, you will find the remote site files.

Now, navigate to the directory containing your website files (usually the public_html directory).

public_html folder

After that, right click on the wp-config file, then select view/edit to modify the contents of the file.

view/edit wp-config file - fix 504 gateway errorNow, locate the line containing the WP_DEBUG settings and then replace the line with the code snippets below.

define( ‘WP_DEBUG’, true);

define( ‘WP_DEBUG_LOG’, true);

Afterwards, save the changes on the file. The WP_DEBUG_LOG settings creates a debug.log file containing a list of all the errors that occurred when you tried to load your website.

The file is located in the wp-content directory on your server. To access it, double click on the wp-content folder.

wp-content folder - fix 504 gateway error

Now, double click on the debug.log file to download to your local machine and then open the file to see all the error logs.

error logs - fix 504 gateway timeout

The error messages can help you pinpoint the cause of the error, thereby speeding up the troubleshooting process.

After troubleshooting your site in debug mode, delete the WP_DEBUG_LOG line of code and then revert the WP_DEBUG settings to false.

Meanwhile, you may also refer to the default server logs for more information about the error.

If your WordPress site uses Apache, you can find the file in the location below.

/var/log/apache2/error.log/

For sites hosted on Nginx server, the log file can be found in this location.

/var/log/nginx/error.log/

Upgrade your Hosting Plan

As your WordPress site traffic begins to grow, the need to upgrade your sites’ hosting becomes paramount due to the increase in requests per second on the server.

Also, if you are on a shared hosting plan and one of the websites on the server begins to grow exponentially. Then, the increase in traffic can affect your site if the server is receiving more requests than it can handle at a time.

To fix this error, you need to contact our WordPress experts to solve the issue, and possibly migrate your site to a managed WordPress host server. Or you can contact your hosting provider to assist with the upgrade.

Conclusion – 504 Gateway Timeout

In this article, we offered a detailed guide to help you understand the 504 gateway timeout error, it’s common causes, as well as steps to take to troubleshoot and fix this error.

However, if you are still experiencing the error 504 after applying the tips in the guide above, you may have to reach out to us so our WordPress experts help you fix the error.

Recommended articles