What Is Error Code 504? - Proxidize

What is Error Code 504?

Image of a computer showing 504 Gateway Timeout. Text on the left reads

One of the most common error codes is error code 504. It is an issue that affects both website owners and website visitors. Knowing how to fix error code 504 is critical to keeping customers from going to your competitors instead.

A big challenge with 504 gateway timeout is that it often does not tell you why it happened. Yes, a gateway has timed out, but what exactly happened, and why?

By reading this article, you will hopefully discover the answer. We will explain what error code 504 is, what causes it, how you can fix it, and how you can prevent it from happening again. It will explore causes and fixes for both website owners and website visitors. No matter where you sit on that pendulum, if you see error code 504, you will know what to do.

A server with a clock on it trying to reach another server. Text above reads

504 Error Code Meaning

Error code 504 lets you know that the server did not receive a timely response from an upstream server that it needed to access so it can complete a request. What this means is that two servers are processing a request and one server times out while waiting for the other. It tends to be the main server that times out while waiting for the upstream server.

The Internet Engineering Task Force defines error code 504 as: The 504 (Gateway Timeout) status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request.

IP rotation, city and carrier targeting,
sticky sessions — control it all via API

Anytime you visit a website, the browser needs to send a request to the web server where the website is hosted. The server will process the request and respond with the requested resources. The server response will include one of many possible HTTP status codes to let you know the response’s status to the browser. 5XX status codes let you know that the issue is from the server, not from something you specifically did wrong.

Error code 504 can be temporary as it could happen because there is too much traffic heading to the server or the website, but it can also take a while because there is a resource on the website that is taking too long to load.

Variations of Error Code 504

You may have noticed we have been referring to error code 504 as 504 gateway timeout. This is because this error code can show up in a variety of ways. No matter how it shows up, it all means the same thing. If you see the number “504” on an error page, it is most likely referring to error code 504. Here are a few other ways the error code might present itself and some additional information that could help you narrow down the exact cause of the code.

  • 504 Gateway Timeout – A standard 504 error message.
  • 504 Gateway Timeout NGINX – Specific to NGINX servers
  • NGINX 504 Gateway Timeout
  • Gateway Timeout Error – Directly lets you know a timeout happened at the server gateway.
  • Error 504
  • HTTP Error 504 – Specifically highlights it as an HTTP status code.
  • HTTP Error 504 – Gateway Timeout
  • HTTP 504
  • 504 Error
  • Server Error – 504 – Emphasizes that the issue comes from the server.
  • Gateway Timeout (504)
  • This page isn’t working – Domain took too long to respond. – The server did not respond in time, letting you know there has been a delay in responding.
  • 504 Gateway Time-out – The server didn’t respond in time.
  • The page request was canceled because it took too long to complete.
  • Or, you could just see a blank white screen.
Image of a desktop showing 504 gateway timeout and a server behind it with a cation sign. Text above reads

What Causes 504 Gateway Timeout

The 504 gateway error tends to be a temporary issue. As it is a 5XX class code, it is a server-side issue but in very rare instances, it could be a client-side issue like internet connection troubles.

If it is a server-side issue, this means that the website server is down or under maintenance. This requires the website owner to fix the server on their end and the user would need to wait until that is completed. Other issues that cause error code 504 include:

  • Connectivity Issues: General network equipment issues can lead to temporary connectivity issues that affect communication across different web browsers, devices, and websites.
  • Proxy Server Issues: Problems with proxy servers can disrupt the communication pathway between your server and the upstream server. This will lead to timeouts.
  • Firewall Issues: Despite their protective nature, firewalls, especially those with DDoS protection and mitigation systems, could mistakenly block requests. This is because of faulty configuration or restrictions on ISPs or Cloudflare.
  • DNS Issues: When DNS servers are unable to resolve the domain name’s correct IP address, you could experience a 504 gateway timeout error. This can be because of DNS configuration, outdated DNS caches, or recent changes in the IP address.
  • Upstream Server Issues: If the upstream server is down or unresponsive, it can lead to error code 504.
  • Web Server Overload: When a server is overloaded with requests or running low on resources, it can slow down or stop responding entirely. This could also cause error code 429 but in most cases, if you have not done anything to initiate the error, it is most likely 504.
  • Limited PHP Workers: Some websites that have insufficient PHP workers can experience delays in processing requests which can cause timeouts.
A desktop showing 504 Gateway Timeout surrounded by possible solutions to fix the error. Text above reads

How to Fix a 504 Gateway Timeout

In this section, we will be providing you with solutions that will help if you are a person visiting a website and you come across the error, or if you are a website owner and have been informed that your site is showing error code 504 gateway timeout.

Some of the most common solutions are, reloading the page, rebooting your network devices, checking proxy settings, checking for DNS issues, temporarily disabling your website’s content delivery network, checking server issues with your host, checking for spam, bots, or DDoS attacks, repairing corrupted WordPress database, checking a website’s plugins and themes, checking error logs, and configuring Apache or Nginx settings. We will explore each one of these solutions in detail.

Reloading the Webpage

The first step to solving a 504 gateway timeout error or, any proxy error code for that matter, is to refresh the page. Most of the time, this would instantly solve the issue. You can also try loading the website in a different browser to rule out the issue and move on to another solution.

Before doing so, you should also check if the website is down for anyone else. Two useful websites to check for downtown are Down For Every or Just Me and Is It Down Right Now? They will let you know if the issue is exclusive to you or if the website is down for everyone.

Reboot Your Network Devices

Since the dawn of technology, the age-old solution to most things not working is — say it with me — “Have you tried turning it off and on again?” A gateway timeout error could be due to problems with your network devices such as a modem or a router.

Rebooting them might fix the issue instantaneously. Unplug the power from the router for a few seconds and plug it back in and see if that fixes things. Just to be extra safe, check every wire’s connection to make sure they are secured correctly.

Check Proxy Settings

While it may be rare for proxy servers to cause error code 504, incorrect proxy settings can sometimes be the reason. Try disabling your proxy and reloading the webpage to see if that will fix the issue. This is a similar step if you are using a Virtual Private Network as while there is a difference between a VPN vs a proxy, they still might be causing some issues to your network.

Check for DNS

A 504 gateway timeout error can be caused by DNS issues on the server-side, the client-side, or sometimes both. The most common issue on the server-side could be the FQDN (fully qualified domain name) not resolving the correct IP address or the DNS server not responding.

This happens when you have just migrated your website to a new server or host. Keep in mind that it is important to wait for the domain’s DNS records to propagate fully. This process can take up to 24 hours.

If you are a client experiencing this issue, you can fix the DNS by flushing your local DNS cache. On Windows, you can clear it by opening the Command Prompt and entering ipconfig/flushdns. On macOS, you can open the Terminal and run sudo killall -HUP mDNSResponder.

Disable CDN Temporarily

Sometimes, the issue could be related to your content delivery network (CDN). If a website’s origin server is not reachable, most CDNs will then serve the full webpage from their cache. However, most CDNs do not enable this feature by default as it is complex to cache dynamic assets on most websites.

A simple way to troubleshoot this issue is to disable your CDN temporarily. If you are using the free CDN Enabler WordPress plugin to link your set assets to the CDN URLs, then you can deactivate the plugin and reload your website to test it. This is similar to if you are using any other plugin such as WP Rocket, Breeze, or W3 Total Cache.

Check Server Issues with your Host

Server issues are a common reason for error code 504. Since most WordPress websites are hosted on Nginx or Apache servers, they are waiting for a response from something and end up timing out. High-traffic and e-commerce websites are more prone to 504 because of server overloads as they generate many uncacheable requests. This issue can happen on any website, including simple blogs.

An overloaded server is not the only reason for a server timeout as there can be many other reasons, including:

  • Slow Server Infrastructure: The server you are using to host your website may not have enough resources to handle the load. It simply hangs up trying to serve the website. The only solution to this problem is to upgrade to a server with better infrastructure.
  • More PHP Threads Needed: PHP threads are used to execute your website’s code. If all the server’s PHP threads are busy, they will build up a queue. When that queue gets too big, old requests will be disregarded which may cause the server to send out error code 504. You can ask your host to increase the number of PHP threads.
  • Firewall Issues: Your server’s firewall could have some errors or it could be improperly configured. A few of its rules might be preventing the server from establishing a connection properly. If you want to be certain that it is your firewall causing the issue, check your server’s error logs.
  • Network Connectivity Problems: Connectivity issues between a proxy server and the web server could cause delays in responding to HTTP requests. If you are using a load balancer, there could be network connectivity issues with it.
  • HTTP Timeouts: These occur when a connection between the web server and the client is kept open for too long. With WordPress sites, this can happen when running WordPress imports. You can resolve this issue with a faster internet connection.

Check for Spam, Bots, or DDoS Attacks

Malicious attackers can bring your web server to a crawl by sending too many requests. If your website is getting spammed by bots or undergoing a DDoS attack, it can overwhelm your server and result in error code 504. You can look at your server traffic and analytics to check for any irregular patterns in the site traffic.

Check to see if a certain IP is generating more traffic than usual. If it is unfamiliar, work quickly to block that IP or temporarily ban it until you discover why they are sending that many requests at once or if their actions are meant to be harmful.

Repair Your Corrupted WordPress Database

Sometimes, error code 504 happens because of a corrupt database. This is due to corrupted database tables or files and can sometimes be caused by a serious security issue such as your website or database being hacked. Repairing the database will depend on the problem. Plugins like WP-DBManager make it easy to diagnose these issues and repair them.

Check Your Website’s Plugins and Theme

Typically, third-party plugins and themes will not cause this error. However, there might be a slight chance that they cause server timeouts by querying for many uncached requests that are generated by the plugin or theme.

The easiest way to solve this issue is to deactivate all your plugins and see if that fixes the issue. If it does, and if you are able to, reactive them one by one until the issue reappears and that will narrow down what the problem is. The issue might narrow down to an outdated plugin as well so always make sure your plugins are up to date.

Check Error Logs

Viewing your error logs can be a helpful way of troubleshooting and debugging 504 errors on your website. They can help narrow down an issue on your website quicker, especially if it is resulting from a demanding plugin. If the host you are using does not have a logging tool, you can enable WordPress debug mode by adding the following code to your wp-config.php file:

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

The WP_DEBUG constant will enable or disable the WP Debug mode. It has two optional companion constants that extend its features. The WP_DEBUG_LOG constant will direct all errors to be saved to a debug.log file inside the /wp-content/directory. The WP_DEBUG_DISPLAY constant will control whether drug logs show up on the HTML page. Setting this to false will hide all errors but you can review them later.

Configure Apache or Nginx Settings

You can edit your server config files to increase resource limits for specific directives. This will help in resolving the error.

For Apache Webservers:

Add the following code to your httpd.conf:

TimeOut 600

This setting will define how long the server will wait for certain requests before marking them as a network timeout issue. You may only add this directive in your httpd.conf file and not in your .htaccess file.

This is because most shared hosting providers do not allow you to modify the httpd.conf file but you can try increasing the value of the LimitRequestBody directive in your .htaccess file.

Next up, add this line to the php.ini file:

max_execution_time 300

The default value is 30 seconds however, you can increase it to allow your site’s PHP scripts to run longer.

For Nginx Webservers:

If you are running your WordPress websites on Nginx and FastCGI Process Manager (PHP-FPM) or you are using Nginx as a reverse proxy for Apache, you can alter the server settings to prevent error code 504.

First, you have to edit your PHP-FPM pool config file. You can find it at the /etc/php7.4/fpm/pool.d/www.conf location in your Nginx server. You can also try running this command in your terminal to edit the PHP-FPM pool config file:

sudo nano /etc/php/7.2/fpm/pool.d/www.conf

Then set the following directive:

request_terminate_timeout = 300

Next, you have to edit your php.ini file which can be located at /etc/php.ini. Once you open the file, add or change the value for the max_execution_time directive to 300 seconds.

Finally, add this code to your nginx.conf file’s location block:

location ~ .php$ {
...
fastcgi_read_timeout 300;
}

Then, reload Nginx and PHP-FPM for the changes to solidify.

sudo service nginx reload
sudo service php7.4-fpm reload

If you are using Nginx as a reverse proxy for Apache, you can make it more forgiving towards server timeouts by adding these directives to your nginx.conf file:

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

Image of a person sitting on a desk in front of a computer that is showing 504. Text above reads

Preventing 504 Gateway Timeout

Congratulations, you now know how to fix error code 504 from the user side and the website admin side. Now, what can you do to make sure you never see 504 Gateway Timeout ever again? Here are some tips and tricks of the trade that you can follow to ensure the code never pops up, or at the very least, you see it less frequently.

  • Optimize Server Performance: Upscale your server capacities to handle high traffic loads. This will prevent bottlenecks that lead to slow response times. Keep an eye on your server’s CPU usage, memory, and disk I/O to spot bottlenecks.
  • Set Up Load Balancing: Implement a server system that will distribute incoming traffic to prevent overwhelming a single server.
  • Implement Caching Strategies: Use efficient caching to reduce direct server requests by storing the most commonly accessed data. This will decrease processing time and enhance speeds.
  • Keep Everything Updated: Make regular and frequent updates to plugins, themes, and your CMS to avoid compatibility issues. Set a day in the month to make sure everything is updated and in the latest version.

As a website owner, these steps are important to take to make sure your website is constantly operational and the risks of encountering error code 504, or any error code for that matter, are lessened. Having your website struck with a 5XX error code can result in customers heading to a competitor of yours, it can damage your SEO, and lead to lost revenue in the long run.

If you are a user seeing 504 Gateway Timeout, unfortunately, there is not much you can do to prevent seeing this error as it is a server-side issue. You can take the steps we mentioned above (trying a different browser, turning off plugins, checking your proxy settings) but ultimately, the solution will come from the website administrator.

Conclusion

Error code 504 stands for Gateway Timeout, meaning the server did not receive a timely response from an upstream server that it needed to access so it can complete a request. This can happen because of a number of reasons such as connectivity issues, firewall issues, proxy configurations, or even a server overload.

Key takeaways:

  • Error code 504 is a server-side issue, meaning most likely it is a problem from the website owner and not something a user did. 
  • In the simplest terms, 504 Gateway Timeout means something happened between you entering the website URL and the page loading. It could be related to an issue within the website that causes the server to timeout before being able to reach it. 
  • For a user, steps to solving the error include refreshing the page, trying again later, trying a different browser, or checking your internet connection or proxy settings. 
  • For a website owner, resolving the issue should be a main priority. Steps to solve it can last anywhere from a few seconds (turning off plugins and themes) to hours on end (adjusting some code in the Nginx server). 
  • If you are a website owner and have had many complaints regarding error code 504, set up weekly or monthly audits to make sure everything is operating as it should and all plugins are up-to-date. 

While 504 tends to be a server-side issue, rarely, the solution can come from the user’s end. You can reload the page, check your internet connection, try a different browser, or see if the issue is exclusive to you or happening to everyone else. If it is happening to everyone else, then it is up to the website admins to take charge and find the solution as quickly as possible or risk losing out on new customers, returning customers, or even their reputation.

Thankfully, resolving error code 504 from the admin side is straightforward if you follow all of the steps mentioned in this article. The next time you see that error message, take a deep breath, come back to this article, and find your solution.


Frequently Asked Questions

Is 504 gateway timeout my fault?

If you are a user, most likely no. If you are a website administrator, it might be. Check your website to make sure everything is up-to-date and your server is able to handle all the requests you have coming in.

Why do I keep getting 504 gateway timeout?

504 is typically caused by server overload, a slow or down upstream server, network connectivity issues, or a misconfigured firewall. If you as a user keep getting the error code, contact your ISP to see if there is an issue from their end that keeps causing the code to appear. If you are a website owner, you will need to do a full audit of your website to discover what the problem is and solve it so it stops happening.

How to get rid of 504 gateway timeout error?

As a user, your best solution is patience until the website owner fixes it. If you are a website owner, you can check your DNS, disable the CDN temporarily, check server issues, check for spam or bots, repair your corrupted database, check plugins and themes, check error logs, and if it still is not working, you will need to configure Apache or Nginx settings.

How long does 504 gateway timeout error last?

The error can last anywhere from a few seconds to two days, depending on the severity of the error and how quickly a website owner can fix it.

Build without limits

Scale projects with fast, reliable infrastructure you can trust.

Related articles

A drawing of a person in a hoodie at a laptop with a fingerprint behind them next to the title
Passive OS Fingerprinting (TCP/IP Fingerprint)

Proxy providers and users go to great lengths to protect their privacy. This extends to

Omar Rifai

How to Test Proxies: 3 Easy Ways

Many of us rely on proxies every day of our professional lives and others of

Omar Rifai

Exploring Web Scraping Tools: From Extensions to Frameworks

In a previous article we introduced the concept of web scraping. We learned that it

Zeid Abughazaleh

Build without limits.

Scale projects with fast, reliable infrastructure you can trust.

Talk to Our Sales Team​

Looking to get started with Proxidize? Our team is here to help.

“Proxidize has been instrumental in helping our business grow faster than ever over the last 12 months. In short, Proxidize has empowered us to have control over every part of our business, which should be the goal of any successful company.”

mobile-1.jpg
Makai Macdonald
Social Media Lead Specialist | Product London Design UK

What to Expect:

By submitting this form, you consent to receive marketing communications from Proxidize regarding our products, services, and events. Your information will be processed in accordance with our Privacy Policy. You may unsubscribe at any time.

Contact us
Contact Sales