Sometimes trying to get access to a web page does not go as planned. You have probably come across the 504 gateway time-out error and wondered what is behind this error message.
In this article, we are going to delve into what the 504 gateway time-out means and what causes it. After looking at the different causes that can generate the error we are going to see the possible solutions.
There are several ways to solve the 504 error and only some of them can be implemented by all users. But what if it’s your site that has problems? Don’t worry, in this guide, we will look exactly into the following: 504 gateway timeout: how to solve the error.
504 gateway time-out: the meaning of the error
The 504 gateway time-out is an error that is part of the HTTP status codes. This type of error tells us what is going on and allows us to understand what interrupted the loading of the page.
This error is part of the HTTP 5xx Server Error status codes which results in a server error. This type of error occurs when the server fails to complete a request, even though it is valid.
It must be distinguished, therefore, from 4xx Client Error that involves, instead, requests with syntax errors, or requests that cannot be fulfilled. For example, errors 403 and 404.
But let’s focus on server-side errors. These include error 502 bad gateway which occurs when the server acting as a gateway (or proxy) receives an invalid response.
The category of server-side errors also includes 508 error. In this case, it is a warning that informs you that the account resource limits have been exceeded.
What about error 504 gateway time-out?
In this case, too, the server acting as a gateway is involved, but in this case, it fails to receive a response within a time limit. This error can come in different forms because it depends on the settings used by the website.
The error can show up as you see in this screenshot, or in a slightly different form.
For example, if you are using Cloudflare’s services and you come across this error, you will be faced with a custom screen that always indicates the same error code.
Usually, the most common forms used to indicate this error are:
- HTTP 504
- 504 Error
- Error 504
- 504 Gateway Time-out
- Gateway Timeout (504)
- Error 504 Gateway Time-out
- HTTP Error 504: Gateway Time-out
- 504 NGINX gateway timeout
- NGINX 504 Gateway Time-out
In each of these cases, the problem is always due to the lack of a response from the server in the maximum time.
But what causes the 504 gateway time-out error?
504 gateway time-out: the causes of the error
As you have seen, an error of this type is encountered when there is a communication failure between an intermediary server and a main server. When too much time elapses before the request is completed, the time limit is exceeded and communication stops.
The problem then occurs for a variety of reasons. It may be that the server is overloaded, not working properly or temporarily out of service.
The error message does not give us any further information about the specific causes. Therefore, often the only way to find the cause of the error is to try to solve it by excluding the causes one by one.
Before we see how to do that, let’s look specifically at what events can cause the error.
Most common problems that generate the error
As we have already mentioned behind the error 504 gateway time-out there can be server errors.
In many cases, it is the infrastructure itself that generates the error. For example, the server may be overloaded. This happens especially when the number of users trying to access the site grows suddenly or in a short time interval.
In such cases, the resources available to the server acting as a proxy will not be necessary to ensure a prompt response to all requests. You may want to consider changing your hosting plan to one that offers more resources or consider changing your hosting. If you choose our shared hosting you can switch to a plan with more resources at any time.
In other cases, however, the overload may be due to DDoS attacks that generate a high number of requests causing the error.
You may also run into the same problem when the resource request comes from a plugin or theme you have installed on WordPress.
A database error can also be responsible for the 504 error on WordPress.
Sometimes the cause of the error is justified, for example, if you are running a script that needs more time to complete its functions. In such cases, you may need to change the settings so that the script can run even if it needs more time to do so.
504 gateway time-out: how to solve it
Since we don’t know the exact cause of this error, the only way to approach it is by exclusion, examining all possibilities one by one.
Since it is an error that involves the server, it is unlikely to be due to the user. However, there are some steps you can take to eliminate any doubt. Let’s start, then, by looking at the user-side solutions.
504 gateway time-out: how to solve it: solutions for users
Let’s see what you can do if the site you’re trying to visit has the 504 gateway time-out error.
Reload the page
As it applies to other errors, the first attempt you can make is always to wait for a while and then reload the page.
Regardless of the browser, you are using you can use the F5 key to do this on Windows and Command + R on Mac.
Restart modem and/or router
Sometimes network errors can be due to the modem or router you use to connect to the network. In these cases, you just need to restart the devices to see if the problem is resolved.
Verify the proxy
If you are using a proxy and some of the settings are wrong, you may encounter errors that prevent you from reaching web pages. Try disabling the proxy and reconnecting to the page.
Change DNS servers
A failure of DNS servers to resolve addresses can result in a 504 gateway time-out. In this case, you can try changing DNS servers from your provider’s to public DNS. You can use Google or Cloudflare DNS for example.
If all the attempts you have made so far have failed, it means that the http 504 error is not your fault. In this case, you can simply wait and reconnect to the page at a later time. Or you can report the presence of the error to the website operators.
504 gateway time-out: how to solve it: solutions for website owners
If you encounter the 504 gateway time-out error while trying to access your website you have several options to try to resolve it.
Check the errors log
An immediate way to identify error causes on your WordPress site is to go check the error logs.
If your host uses cPanel you can view the errors from the Metrics panel by clicking on Errors, as you see in this screenshot.
If you can’t access the error logs directly from the control panel you can also use the WordPress debug mode. To do so you just need to edit the wp-config.php file by adding this code:
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );
By doing so, the debug mode will be activated and a file called debug.log will be created in which the recorded errors will be stored.
The file will be saved in the wp-content folder so you only need to access the folder and open it to be able to see it. You can always use the cPanel file manager or the control panel used by your hosting.
In case you are using a CDN (Content Delivery Network) the problem may come from the CDN servers. In this case you can try temporarily disable the CDN.
Verify themes and plugins
Among the causes of 504 gateway time-out error on WordPress some times the real culprits can be third-party applications.
There are several ways to disable plugins on WordPress. If you can’t access the dashboard, you can just log in via FTP to the server or use the file manager from cPanel.
In both cases the folder we are interested in is called plugins and you will find it in /public_html/wp-content/. To deactivate all plugins on the site, simply rename the plugins folder to another name.
This way you will understand if the error is due to one of the plugins you are using.
Increase timeout limits and script execution time
As we saw earlier, another cause of the error can be a PHP script. Some scripts need a longer execution time in order to run. Especially those used for site maintenance or when it comes to importing a large amount of data.
In this case, to solve the 504 gateway time-out error, all you need to do is to change the settings in the php.ini file. The value you will have to change is the maximum execution time, that is:
max_execution_time = 30
The default setting is 30 seconds, but depending on your needs you can change the value to allow more time.
You can also change the timeout limit, i.e. the maximum time within which requests must be executed before generating a timeout error.
With Apache, you can do that by modifying the settings of the HTTP server configuration file httpd.conf. The value you have to change is the one next to TimeOut.
With Nginx you have to change the timeout settings from the configuration file, usually nginx.conf. I don’t specify the path to the configuration file because it varies depending on your installation.
The values to modify are those related to timeout, so you’ll find proxy_read_timeout, proxy_connect_timeout, proxy_send_timeout and send_timeout. If these directives are not present you can always add them yourself in this way:
proxy_read_timeout 300; proxy_connect_timeout 300; proxy_send_timeout 300; send_timeout 300;
By doing so the timeout will be set to 300 seconds, but of course you can set the value you prefer according to your needs. After you’re done you’ll have to restart nginx for the changes to take effect.
If you were not able to solve the problem on your own, you can contact the customer support of your hosting. If you are our customer you can open a ticket and receive dedicated support with a quick service via the phone or email.
In this article, we have seen the causes of 504 gateway time-out error. After looking at the common issues that can trigger the error we then focused on resolving it.
We’ve seen what you can do if you’re trying to access someone else’s site, and what checks to make in case the problem affects your own site.
Did you manage to solve the problem by following our guide or do you still have doubts? Let me know in the comments below.