How to Fix the 504 Gateway Timeout Error on Your WordPress Site

How to Fix the 504 Gateway Timeout Error on Your WordPress Site

The 504 gateway timeout in WordPress is one of the worst errors you can have. Not because it’s difficult to fix but because it impacts service. It usually results in downtime and affects the customer experience.

That’s why they are so important to fix.

The 504 gateway timeout error is a common one. It’s one of many 5xx HTTP errors you’ll see while online because the internet depends on so many interconnected systems all working in concert.

Any interruption to one of those systems can cause issues.

That’s the case here.

This post is going to explain what the error is, what causes a 504 gateway timeout in WordPress and what to do if it happens to you.

Let’s get going!

What Is the WordPress 504 Gateway Timeout Error?

504 google error example

The WordPress 504 gateway timeout error is an HTTP error. It is caused by a proxy or gateway server not receiving a response from the server that hosts your website.

Picture the scene. You type in a URL in your browser, there’s a pause and then the website appears. It’s like magic, type in the URL, wait a second or two and the page loads.

What you don’t see is the process behind that query from your browser.

All web queries will work a little like this:

  1. The browser queries DNS and is directed towards your web host so it can deliver a copy of the requested web page.
  2. Your host will have a proxy server that handles requests and then forwards them on to your web server. Every visitor to your website will land on this proxy server.
  3. The proxy will look up the IP address or domain, find the physical server and route the traffic to the web server that hosts your website.

When everything works well, this process is seamless and takes a second or two.

If the proxy cannot contact your web server for any reason, it will return an HTTP 504 error to your browser.

To help keep the internet flowing, HTTP has a timer built into it. Once an HTTP query is sent, there is a finite amount of time for the web server to respond.

If it responds in time, it’s all good and your web page loads.

If the server doesn’t respond in time, the proxy flags an HTTP error. In this case, HTTP 504.

Proxy Servers

Proxy servers are used a lot in networking. It’s a catch-all name for servers that can perform several functions:

  • They act as gatekeeper to networks and will often run firewalls that work alongside network appliances for defense in depth.
  • They work as load balancers, dividing traffic across multiple network servers.
  • They can act as mini VPNs, adding a layer of privacy to communications.
  • They can divide networks along with routers, keeping internal IP addresses private while allowing the public to access web servers.

What Causes 504 Errors in WordPress?

So, you now know how the basic server architecture works, what could cause a proxy to not be able to communicate with a web server?

It could be a number of things, including:

  • Physical fault with the web server
  • Fault with the link between the web server and the network
  • Data mismatch between the IP address of the proxy and the IP address of the web server
  • Planned work within the organization
  • DDoS attacks on the web host
  • Web server simply too busy to respond in time

The one thing you need to remember if you see a 504 error is that it isn’t usually your browser or your computer. It’s most often a network error on an external network.

However, as you’ll see in a minute, there are tests you can run locally to make sure the error is network and not your device.

How Do 504 Errors Impact Your Website?

coding stock image

The reason WordPress 504 gateway timeouts are serious is because they impact visitors. They won’t be able to visit your site, which has the obvious consequences.

If the cause of the error is a busy server, a portion of your visitors will get through, so will cause a reduction in service.

If the cause is a fault, planned work, data mismatch or something else, chances are nobody will get through. That means a total loss of service on your website.

Not only do 504 gateway timeouts in WordPress impact visitors, they can also impact your SEO. If you don’t notice the error and your site is crawled while it’s not contactable, or Google is notified via a bot, it can delist the page.

That’s a worst-case scenario but we use it to illustrate just how serious a 504 gateway timeout in WordPress can be.

List of HTTP 5xx Codes

There are 12 commonly used HTTP 5xx codes. All of them refer to some kind of network issue that prevents the relevant server performing its tasks.

Those codes are:

  • 500 – Internal server error. Displayed when a request cannot be fulfilled but there isn’t enough information to identify why.
  • 501 – Not implemented. A rare error that is shown when the server doesn’t recognize the query or cannot respond properly.
  • 502 – Bad gateway. Where the server received an incorrect or invalid response from the upstream (web) server.
  • 503 – Service unavailable. The server is physically unavailable due to maintenance or is overloaded.
  • 504 – Gateway timeout. Where the gateway (proxy) server didn’t receive a reply in time from the upstream (web) server.
  • 505 – HTTP version not supported. The server doesn’t support the protocol requested.
  • 506 – Variant also negotiates. Incorrect server configuration for the query.
  • 507 – Insufficient storage. The proxy server is unable to store the browser query and/or response.
  • 508 – Loop detected. The server detected an infinite loop within the query.
  • 509 – Bandwidth exceeded. Unofficial HTTP code used by web hosts to control bandwidth use by customers.
  • 510 – Not extended. The HTTP request includes an extension the proxy server cannot support.
  • 511 – Network authentication required. Client needs to authenticate to contact the upstream server.

How to Fix 504 Errors in WordPress

If an HTTP 5xx error is a network error, is there anything you can do about it?

A couple of things actually. You can:

  1. Troubleshoot locally to make sure it isn’t an issue with your browser or device
  2. Troubleshoot your website to make sure it isn’t a configuration issue
  3. Check with your web host to check it isn’t a physical problem on their network

You can do these checks in any order you like but we recommend this order. Checking locally takes a couple of minutes. Checking your website doesn’t take long and not all web hosts are as forthcoming as they should be when it comes to downtime.

Feel free to switch steps 2 and 3 around if you prefer though!

The 504 gateway timeout error isn’t specific enough to tell us whether the proxy server didn’t get a response from the web server or your website. Therefore, we can do some basic troubleshooting ourselves to try to identify the source of the error.

If you don’t fix it by the end of this article, it’s time to report the error to your web host.

Before we get into that, first it’s often useful to spend a minute checking the fault isn’t local to you. While the 504 error is network, it’s up to the browser to manage communication and it isn’t unknown for a browser to get a little mixed up.

Browsers also cache pages for efficiency. If it caches the 504 page, even if your website is back up, it could still be showing you the cached version.

That’s why we check the local situation first.

So, before we go troubleshooting your website, let’s make sure it’s not your browser or computer!

1. Reload the Web Page

The easiest way to assess the 504 error is to retry the website. Give it a few seconds and then try to revisit the website.

If the error was a result of server or network load, retrying may work.

If it doesn’t, force a page refresh in your browser to request a new copy of the page.

For a browser refresh use:

  • Chrome on Windows: Ctrl + F5
  • Chrome on Mac: Command + Shift + R
  • Firefox on Windows: Ctrl + F5
  • Firefox on Mac: Command + Shift + R
  • Safari: Command + Option + R
  • Microsoft Edge: Ctrl + F5

You could also try a different browser just in case it’s a cookie or cache issue.

2. Reboot Your Devices

While rare, you could also reboot your phone or computer to make sure there isn’t an internal issue causing issues with networking. It’s rarely the cause of a 504 error but as it’s easy to do and relatively painless, it’s worth a try.

If you still see the error after a device reboot, you could also reboot your router just to make sure.

3. Disconnect From Your VPN

Windows VPN setting

If you use a VPN, disconnect from it and retest. VPNs use a version of a proxy server at your end so can occasionally cause errors.

Disconnect from your VPN and retry the website. If necessary, try the force reload method above to request a fresh copy of the page to make sure the website is live again.

4. Check Your DNS

Worldwide DNS Propagation Checker

As a website visitor, you would expect any issues with your DNS settings to also impact other websites.

As a website owner, if you have just moved your website to a new host, the DNS settings may not have propagated yet or there may be a mismatch in the settings.

Any DNS change can take up to 48 hours to work its way across DNS servers and you may be within that period.

There is an exceptionally useful website, DNSMap that can show you the status of any DNS propagation across the globe.

If your change has propagated, log into your web host and double check the DNS settings and name server set for your website.

Those are all the checks you can do locally to remedy 504 errors. Now we’ll start checking your web host and website for issues.

5. Check Your Server Logs if You Have Them

cPanel ERROR

Logs are both intimidating and amazingly useful in troubleshooting. If your web host provides access to server logs on your hosting plan, it’s a good idea to use them.

If your host uses cPanel, accessing logs is simple.

  1. Log into cPanel
  2. Navigate to Metrics and select Errors

If the server picked up errors, they should appear in the new window that opens up.

If you don’t see any logs, don’t take it as everything is good. Different web hosts handle logs differently. Some will include them by default while others will offer minimal logs.

If your web host doesn’t use cPanel, there should be an area for logs within your hosting dashboard.

If you use a WordPress log plugin, don’t forget to check those too!

6. Check the WordPress Firewall

WordPress logs

If you use a WordPress security plugin that has a firewall, you can check it isn’t causing the 504 gateway timeout in one of two ways.

You can look at the logs within the plugin or you can disable it temporarily to see if service resumes.

Much will depend on how comfortable you are with logs or whether your security plugin supports them or not.

The easiest way to check if the firewall is causing the 504 gateway timeout in WordPress is to disable the security plugin and retest.

If you can connect to your website properly, something within the plugin is stopping traffic.

If the error is still apparent, it isn’t your security plugin so feel free to enable it again.

7. Check Any New WordPress Plugins

WordPress plugins screen

Have you added any new WordPress plugins lately? Added a new security or firewall plugin? Added a CDN plugin or any type of plugin that would impact traffic?

If so, disable the plugin and retry the website. The plugin itself may have caused the error or many have added an entry in your .htaccess file that could be stopping responses from your website to the proxy server.

Disabling the plugin should also remove that .htaccess file entry.

8. Disable All WordPress Plugins

Let’s take that a step further and disable all the plugins on your website. If you have been using them from before the error happened, chances are it isn’t a plugin causing the issue but it’s useful to check.

However, if a plugin was recently updated and that update introduced an error, it could be causing gateway timeouts.

Fortunately, newer versions of WordPress have a neat tool to do that.

  1. Navigate to Plugins and Installed Plugins
  2. Check the box at the top next to the word Plugin.
  3. Select the Bulk Actions menu and select Deactivate
  4. Select the Apply button next to it

This process will deactivate all your WordPress plugins at once. Now you can retest to see if the error is still present or not.

If the error is still present, you can repeat the above but select Activate instead of Deactivate.

If the error disappears, you should enable one plugin at a time and retest. As soon as you begin seeing the error again, undo the last step, retest and you should have identified the cause of the error.

9. Test Your WordPress Theme

Activate different WordPress theme

It is unlikely that your WordPress theme is causing 504 gateway timeouts, but it’s a simple test to make.

All you’ll need to do is activate the default Twenty Twenty-One theme, test and enable your theme again.

  1. Select Appearance and Themes in your WordPress dashboard
  2. Hover over Twenty Twenty-One and select Activate
  3. Wait until the new theme has activated and retest in your browser. If the error remains, you can switch back your theme.

If the error disappears, there is something in it that is stopping your website functioning normally.

A theme should never impact a website in this way. If yours interrupted service, consider switching to Astra.

10. Check Your Website’s htaccess File

Website htaccess file example

We mentioned a moment ago that plugins can add entries into your .htaccess file as part of their normal operation. Disabling a plugin should remove any entries and is good enough for testing.

As .htaccess file controls who can access your website, it can also cause a 504 gateway timeout in WordPress.

Let’s check the file now.

You’ll need access to your web host’s file manager for this to work.

  1. Log into your web host and navigate to the file manager
  2. Navigate to the public_html folder and look inside
  3. You should see WordPress files including .htaccess
  4. Select the .htaccess file and right click
  5. Select Copy and name the copy .htaccess.bk
  6. Select the original .htaccess file, replace everything with the code below and save the change
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Now retest access to your website to see if the 504 gateway timeout error is still there.

If it is, you can delete the .htaccess file and rename .htaccess.bk back to .htaccess and everything will be as it was.

If the 504 gateway timeout error has gone, there is an entry in there stopping your website working normally.

You can work through it line by line or disable your plugins and enable them again one at a time so they rewrite to the file.

It’s important to perform these steps one at a time and retest to identify the plugin that’s adding the erroneous entry. Once you identify the plugin, find an alternative or look on the plugin’s forum for advice.

11. Check Your Website’s CDN

504 CDN error example

If you use Cloudflare or other Content Delivery Network (CDN), it could be part of the problem. If your web server is down and your CDN is trying to contact it rather than serve a local cache, it can result in the 504 error.

You can see if it’s a Cloudflare CDN issue as the company adds their own name to the HTTP page. You should see a 504 Gateway Timeout screen with ‘cloudflare-nginx’ underneath.

Other CDNs may do the same thing.

The easy way to check to see if it’s your website CDN causing the issue is to turn it off.

If you have tried all these steps and you still cannot fix the 504 gateway timeout in WordPress, it’s time to contact your web host. It could be a physical server or connection issue causing the problem.

Can You Prevent 504 Errors in WordPress

You can perform a couple of basic steps to help prevent 504 gateway timeouts. They won’t prevent configuration issues within WordPress or physical server errors but they may help.

They are also purely optional.

Check/Change Server Settings to Avoid 504 Errors

The first change you could make is to extend the timeout in Apache if you use that instead of Nginx.

You will need access to the httpd.conf file to make this change. You should find that in the root of your host’s file manager.

Typically, you’ll find the http.conf file in one of the following locations:

  • /etc/apache2/httpd.conf
  • /etc/apache2/apache2.conf
  • /etc/httpd/httpd.conf
  • /etc/httpd/conf/httpd.conf

If you don’t see it, you may not have access to it so move on to the next step.

If you can see it, right click, select edit and add the following code. Then save the file.

TimeOut 600

This may give the server enough time to run any processes that are taking too long.

Increase PHP Max Execution Time

increase PHP max execution time

If you cannot access the httpd.conf file, you could modify your php.ini file instead. We can extend the execution timeout to achieve the same goal, just using PHP.

You’ll find php.ini in your website root in the same directory you found .htaccess.

  1. Right click php.ini and select Copy.
  2. Call the new file php.ini.bk
  3. Select the original, add the following code to the end and select Save.
max_execution_time 300

If your website works properly, you can leave the backup file in place. If things go wrong, delete the file you just changed and rename php.ini.bk to php.ini. Everything should now be back as it was.

Final Thoughts

Troubleshooting a 504 gateway timeout in WordPress is a process. The fault could be your browser, DNS, VPN or something else. It could also be your website or your web host.

Like most troubleshooting, finding the fault and fixing it is a process of elimination. We begin easy with browser refreshes and gradually work our way towards editing files.

While it may seem in-depth and complex, as long as you follow these steps, you should be fine.

Do you know of any other fixes for the 504 gateway timeout in WordPress? Know of other proven techniques to prevent them? Have anything to add? Tell us about it below if you do!

Join 635,020 Subscribers

Get exclusive access to new tips, articles, guides, updates, and more.

Leave a Comment

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

Scroll to Top

Download is Just A Click Away!

Be among the first to try the beta version of Astra’s Header Footer Builder. Filling the form will ensure you’ll be the first to learn about updates and features.

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.