WordPress Tutorial

How to Fix 504 Gateway Timeout Error in WordPress

504 Gateway Timeout Error

504 gateway timeout is one of the HTTP status codes that a server can send back when it was unable to complete a request. While it is less frequent than 500 internal server error or 502 bad gateway error, everyone has encountered it at least a couple of times while browsing the internet. Hence this guide focuses on what 504 gateway timeout error is and how to fix it in WordPress.

When you visit any website, it generates requests and sends them to web servers that hold the required elements. Each time a request is handled, the server sends back an HTTP status code with the requested resources. By default, the HTTP status code is not displayed unless something went wrong in the process.

What is 504 Gateway Timeout?

HTTP status codes beginning with the digit “5” are server-side errors. They pop up whenever it’s impossible to complete a request due to a miscommunication between several servers.

504 gateway timeout error is an HTTP status code which appears when one server does not receive a timely response from another server that acts as a gateway or proxy. In short, it means the server was unable to complete your request within the given time frame.

504 gateway timeout error displayed as HTTP Error 504504 gateway timeout can also come in different shapes and sizes. For example:

504 Gateway Timeout nginx
Gateway Timeout Error
HTTP Error 504
504 Gateway Time-out – The server didn’t respond in time
HTTP Error 504 – Gateway Timeout

How to Fix 504 Gateway Timeout Error

While in most situations the cause of 504 gateway timeout errors come from the server-side, they may also pop up due to issues or misconfigurations from the user-side. Thus, we’ll go through the basic troubleshooting steps with both options in mind. Part of the solutions are suitable for WordPress, but most of them can be applied to any website.

1. Refresh the Page

The first step to troubleshoot 504 gateway timeout error is the simplest one. Wait a couple of minutes and refresh the page. It might be that the server is receiving more requests than usual at the time and is unable to handle more.

While you wait, you may use online tools that check if the website is down. It’s a great way to confirm whether the problem is related to the local network. Checking if the website is down due to 504 gateway timeout error using online tools

2. Try a Different Browser

In case the website is up, but you still see the 504 gateway timeout error, try changing up your browser to a different one. Clearing browser cache or using incognito mode can also help verify if the issue browser related.

3. Flush DNS

504 gateway timeout can sometimes be a result of incorrect or outdated DNS cache, but it is not hard to clear it. The way of doing it differs depending on your operating system. Here’s a tutorial on how to flush DNS on Windows, Linux, and Mac OS.

Temporary switching the DNS server to Google Public DNS can let you rule out if the HTTP status code appears due to a DNS problem. Though we mostly recommend this option for advanced users.

4. Test with Different Devices

Try loading the website on a different computer, network connection, or a mobile phone. In case none of the above solutions fixed the 504 gateway timeout error, this step will let you confirm if it is a local issue or a server-side problem.

5. Check Error Log

The 504 gateway timeout error may also be a cause of recent website changes or updates. The quickest way to find out is by checking the error log for any hints. WordPress users can enable error message logging by adding the following 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 entries will appear in wp-contents/debug.log file.

WordPress error log file

6. Check Plugins

While troubleshooting a 504 gateway timeout error, it’s advisable to look through your website plugins and extensions. In WordPress, plugins related to caching can be the culprit. Outdated or incompatible plugins may also cause problems. Hence disabling all of them temporarily will let you know if you’re digging in the right place.

To disable all WordPress plugins, navigate to the wp-content directory and give the plugins folder a different name.

Disabling all WordPress plugins via FTPIf your site works fine when all plugins are off, the next step would be to locate which one causes the HTTP error 504. Rename the plugins directory back to its original name and this time try to disable them individually.

Disabling WordPress plugins one by one

7. Check CDNs

If you’re utilizing a CDN to serve content faster, you should check if everything is okay from that side. One of the most frequently used solutions is CloudFlare, which acts as a CDN and a DDoS mitigation service. While using it, you can encounter two version of the 504 gateway timeout error.

504 gateway timeout error in CloudFlare - version 1The following version of 504 error appears when the issue is on CloudFlare’s side. The best approach is to contact CloudFlare support or disable it entirely. However, if you turn it off, you may have to wait a couple of hours for the DNS to propagate.

504 gateway timeout error in CloudFlare - version 2The below-shown version means that the problem is with the current web hosting provider.

8. Tweak Server Settings

If you’re using VPS hosting, there are a few extra things you can try to fix the 504 gateway timeout error. They would involve tweaking the server settings and increasing specific resource limits.

Apache

Apache users may increase the default timeout value in the httpd.conf file. For example:

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

Furthermore, increasing the max_execution_time limit in php.ini can also bring positive results:

max_execution_time 300

Save the changes, restart apache, and re-check. The 504 gateway timeout error should be gone if the cause was insufficient request timeout value.

Nginx

If your VPS utilizes Nginx, try increasing the following values in /etc/nginx/conf.d/timeout.conf:

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

It’s also advisable to increase the max_execution_time in php.ini:

max_execution_time 300

Once the changes are saved, restart Nginx and try to reach the website again.

9. Contact Customer Support

In case the 504 gateway timeout error persists after following all the above solutions, it’s advisable to contact the web hosting support staff. Try to describe what steps you took to troubleshoot the issue and provide as much information as possible to speed up the process.

Conclusion

In this guide, we’ve overlooked the common steps to troubleshoot and fix a 504 gateway timeout error. If you have any tricks, tips, or extra solutions for fixing this HTTP status code, let us know if the comments below!

About the author

Gediminas B.

Gediminas is a passionate content writer and SEO geek at Hostinger. He started his journey at customer support and aims to use his gathered knowledge to create the most epic content the world has ever seen. From WordPress to server management, there's no topic he can't cover! He also likes cats.

2 Comments

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • You are a life saver! This pesky 504 message kept bugging my site for such a long time. My host had no clue what happened. I started investigating my error log as you suggested and found out that a few WordPress plugins created many error entries. After deleting these plugins, my website works perfectly. No more error now.

    It seems like Hostinger has a solution for everything. I’m starting to consider moving my website to you guys haha!

    • I’m glad to hear you were able to fix your website. And the doors of Hostinger are always open for you, Rajma! 😉

Have a website?

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in WordPress Tutorial
502 bad gateway error
How to Fix 502 Bad Gateway Error in WordPress

Close