504 Gateway Timeout: What it is and How to Fix it

Introduction

A 504 Gateway Timeout error occurs when a server fails to receive a timely response from another server it is trying to communicate with. The error can be a frustrating experience for the website visitor, but also for website owners, as it leads to traffic loss and customer dissatisfaction and affects online reputation.

In this article, you will learn what the 504 Gateway Timeout error is and how you can fix it.

504 Gateway Timeout: What it is and How to Fix it

What Does 504 Gateway Timeout Mean?

The 504 Gateway Timeout error means that the server responsible for loading a website in your browser took too long to respond and failed to complete the request on time. When you try to visit a website, the browser sends a request to the web server hosting the site. In a successful scenario, the server returns a 200 OK status code and displays the web page.

However, if the server does not complete the request in the expected timeframe, the browser displays the 504 Gateway Timeout error. The error indicates that the server acting as a gateway or proxy failed to receive a prompt response from an upstream server required to fulfill the request.

Causes of 504 Gateway Timeout

There can be multiple causes of the 504 Gateway Timeout error. Some of them include a temporary traffic overload on the website or a resource taking too long to load.

The following are the most common causes of a 504 error:

  • Firewall issues. Some firewalls block requests from specific ISPs or CDNs due to their DDoS protection and mitigation systems.
  • Unresolvable domain. This is a domain that cannot be resolved to an IP address, resulting in the inability to access the website or associated service. The issue commonly happens if you have recently moved a website to a different IP address or hosting nameserver.
  • Connectivity issues. Getting the error on multiple devices connected to a single network can result from temporary connection issues on your network equipment.
  • Server overload. A web server running low on resources cannot handle an increase in traffic, causing it to overload and respond to requests slowly, which results in a 504 error.
  • Insufficient PHP workers. PHP workers are processes or threads within a server environment that handle incoming requests and execute PHP scripts. If there are not enough PHP workers, the website might fail to process multiple requests.
  • DNS issues. Some DNS (Domain Name System) issues include an incorrect DNS configuration or an outdated or corrupted DNS cache.

Note: Learn how to flush DNS cache in Windows, Linux, and macOS.

504 Bad Gateway Timeout Variations

The 504 error can manifest in different variations, contexts, and scenarios, depending on the browser, server, and operating system. However, despite the different variations, the 504 error is generally related to the server not receiving a timely response from an upstream server.

Following are the different variations of the 504 error:

  • 504 Gateway Timeout NGINX

NGINX is a popular web server software that can act as a reverse proxy, load balancer, or HTTP cache. If NGINX does not receive a response from the upstream server within a specified time limit, it returns a 504 Gateway Timeout error to the client.

504 error caused by nginx.
  • Gateway Timeout Error

The gateway timeout error is another variation of the 504 error resulting from a request timeout.

A gateway time-out variation of the 504 error.
  • HTTP Error 504

Google Chrome can sometimes print the error description as HTTP ERROR 504. The code and the message appear that the requested site cannot be reached.

HTTP error 504 in Google Chrome.
  • Error 504 or 504 Error

On Android OS, the error can appear only as Error 504, with no additional information.

The 504 error in Android OS.
  • 504 Gateway Time-out. The server didn’t respond in time.

The error states that the server did not respond in time, thus resulting in a 504 error.

Gateway timeout error in a browser.
  • This site can't be reached. Domain took too long to respond.

The message "This site can't be reached. Domain took too long to respond" also indicates that the browser could not establish a connection to the requested domain within a reasonable timeframe.

Connection timed out error in Chrome.
  • HTTP Error 504 - Gateway Timeout

The error may also appear on macOS as a variation shown in the screenshot below.

Error 504 in macOS.

How to Fix 504 Gateway Timeout

In most cases, the cause of 504 errors is on the server side. Occasionally, the error may result from issues on the client side. This section of the article lists some basic troubleshooting steps for website visitors and website owners.

Refresh the Page

Refreshing the page resolves the 504 Error if the cause of the error is high traffic on the website. If the server is receiving more requests than it can handle, refresh the page to try and get the server to complete your request.

Refresh the page by clicking the Refresh button in your browser or press F5 on your keyboard. If you are using macOS, press the Cmd + R buttons. You can also clear the cache and force refresh the page by pressing Ctrl + F5.

To check if the website is down for other visitors, use web tools such as Is It Down Right Now or OutageAlert.

Check Proxy Settings

Using a proxy server to browse the Internet privately could be the reason for a 504 error. Some proxy servers block access to certain web pages based on their IP address. Alternatively, incorrect proxy settings also lead to 504 errors.

Check if your proxy settings are causing the issue by disabling them on your machine and then reloading the page. For example, follow the steps below to disable the proxy in Windows:

1. Click the Start button and select the gear icon to open the Settings app.

2. Select the Network & Internet icon.

Network and internet settings in Windows.

3. Select Proxy from the left pane and turn off the Use a proxy server switch.

Proxy settings in Windows.

4. Reload the website to see if the error is gone.

Restart Router

If the website is down only for you, and none of the solutions above work, incorrect settings or hardware issues may cause the 504 error. Try restarting your network device and then reloading the website to see if the error is gone.

Contact Website Admin

If the error persists and occurs on different devices and browsers, consider contacting the website administrators. If there is a 504 error on the website, they are likely already fixing it.

You can also check the website's social media accounts, if they have any, to see if there is any information on the issue.

Check Resource Usage

Website owners can check with the web host to see if their website has reached hosting plan limits. If that is the case, upgrading to a hosting plan that provides more resources to meet the website's needs is the solution.

Change PHP Execution Time

If the resource amount is not the cause of the 504 error, try extending the maximum execution time of PHP scripts. If a PHP script takes longer to execute than the defined duration, it can cause a server timeout error.

This troubleshooting step prevents marking the scripts as an error mid-process. To extend the maximum execution time, edit the .htaccess file, install the Google Pagespeed Insights plugin, or change the PHP configuration using your cPanel.

The default value for script execution time is 30 seconds. Increase the value of max_execution_time to 60 and save the changes. You can also increase the value further to 120-180 seconds if the problem persists.

Configure DNS Settings

DNS issues can cause a 504 error both on the client and server side. Server-side issues occur on websites with unresolved IP addresses, especially if your website was recently moved to a different domain or server and the change still needs to take effect globally. It takes between 28 and 48 hours to complete DNS propagation.

Client-side DNS issues can be resolved by flushing the DNS cache from your operating system. Flushing the cache eliminates corrupted and outdated cache files from the system, which could be the cause of the 504 error.

Check the Error Log

Check the error log file to see if any corrupted code on the website is causing the 504 error. To find the error logs, navigate to the /wp-content/ directory using your File Manager or FTP Client:

Opening the wp-content folder using a FTP client.

Inside the directory, locate the debug.log file. The file contains all WordPress errors, warnings, and notices that were logged.

Check Plugins

Outdated, incompatible, or incorrectly configured third-party WordPress plugins can cause a 504 error. For example, some caching plugins send requests to the server, which increases PHP workers' workload, and in turn, it can trigger the 504 error.

Temporarily disable all plugins to check if the error persists and if the cause is a faulty plugin. Using a File Manager or FTP Client, navigate to the /wp-content/ directory and rename the plugins directory to disable all the WordPress plugins.

If disabling the plugins resolves the 504 error, find out which plugin is causing the 504 error. Restore the directory to its original name and disable the plugins one by one to pinpoint the source of the problem.

Check CDN

If you use a CDN (content delivery network), check whether it works as intended. Cloudflare is one of the most popular CDN solutions that also acts as a DDoS mitigation mechanism.

If the 504 error clearly states that there is an issue with Cloudflare, you have found the cause. Check the Cloudflare system status to determine whether the company announced network issues.

If Cloudflare is the cause of the issue, the fastest way to solve the problem is to contact them and request support. Another solution is to disable the CDN and wait until the DNS is fully propagated.

Conclusion

This article has explained what the 504 Gateway Timeout error means and its variations and provided some troubleshooting steps for website visitors and website owners.

Next, learn about the 520, 523, 524, or 521 Error, or see how to fix Cloudflare 522 Error to ensure your website's stability and performance.

Was this article helpful?
YesNo
Bosko Marijan
Having worked as an educator and content writer, combined with his lifelong passion for all things high-tech, Bosko strives to simplify intricate concepts and make them user-friendly. That has led him to technical writing at PhoenixNAP, where he continues his mission of spreading knowledge.
Next you should read
Troubleshooting DNS Issues {nslookup, dig, host & More}
November 17, 2021

DNS (domain name system) stores information related to domain names as a distributed database. The client-server service translates domain names to IP addresses and vice versa.
Read more
Localhost Refused to Connect - How to Fix the Error
May 16, 2024

Localhost refused to connect is a common error that may occur when working on a local machine. In this article, you will learn the most common causes of the localhost refused to connect error...
Read more
How to Troubleshoot ERR_TOO_MANY_REDIRECTS
March 3, 2022

The ERR_TOO_MANY_REDIRECTS error occurs when the browser is redirected to a different URL, which in turn points back to the original one, creating a redirection loop.
Read more
403 Forbidden Error - What Is It and How to Fix It
December 19, 2024

When a web server denies access to a particular webpage or web content, it displays the 403 Forbidden error. Different web servers report different variations of the 403 Forbidden error...
Read more