504 timeout Nginx error- How we solve it for you

504 gateway timeout niginx

Table of Contents

Website errors are always a mess for users.

Sometimes the errors are completely clueless and users may not know how to fix it.

A typical example of such an error is “504 timeout error,” in Nginx, a tricky error to resolve.

That’s why, we often get requests from our customers to fix “504 timeout Nginx ” error as part of our Technical Support Services.

Today, let’s understand what is 504 timeout error in Nginx and reasons on why this error occurs, also the way 1 onlyhost ’ Engineers fix it.



What is 504 timeout Nginx error?

Nginx is an open-source, high-performance HTTP web server. Now, it is used for serving web pages, as reverse proxy, caching, load balancing, media streaming, and more.

Furthermore, a 504 Nginx timeout error is one of the HTTP status code. Usually, the server sends back a 504 HTTP code when the request is not completed.

In addition, this is a common error, most likely due to process exceeding the PHP execution time limit or the read timeout settings of FastCGI.


Top reasons for the “504 timeout error,” and quick fix for it in Nginx

From our experience in managing server, our Support Engineers often deal with this error and fixe it for our customers.

Now, let’s see how our Technical Team exactly fixed “504 timeout Nginx” error with different methods.


1. Adjustment in timeout settings

Usually, adjusting the timeout settings is one of the methods to fix 504 error.

Recently, in one of the customer’s server, Nginx was set up as a proxy server with PHP-FPM disabled. To fix the 504 error, we increased the timeout values in the file “timeout.conf”.

1.  We edited the file /etc/nginx/conf.d/timeout.conf and added the following parameters to file “timeout.conf”.

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

2. Finally, we restarted the service.

service nginx restart


2. Modifying Other Nginx settings

Sometimes, increasing values in “timeout.conf” doesn’t resolve this issue. Then, our Support Engineers add codes in “nginx.conf”. In addition, if the values are already preset in “nginx.conf”, we will increase the value.

1. We open the file /etc/nginx.

2. Then, we add the following snippet to “timeout.conf”.

client_header_timeout 3000;
client_body_timeout 3000;
fastcgi_read_timeout 3000;
client_max_body_size 32m;
fastcgi_buffers 8 128k;
fastcgi_buffer_size 128k;

3. Finally, we restart the service.

service php-fpm restart
service nginx restart


3. Modification in PHP settings

At times, to fix  504 Nginx timeout error, we may need to modify the php settings in php.ini file.

Recently, our Support Engineers had to raise the value of max_execution_time  in php.ini file.

In CentOS, we located “/etc/php.ini” and  increased the value “max_execution_time” by adding the following entry.

max_execution_time = 150

Additionally, we raised the value of request_terminate_timeout setting in php.ini file too.

request_terminate_timeout = 150


4. Nginx virtual host configuration settings

Similarly, fix may involve modifying Nginx virtual host configuration too. Here, to fix the php file access, in Nginx virtual host configuration, our Support Engineers add FastCGI read timeout variable.

location ~* \.php${
include fastcgi_params;
fastcgi_index index.php;
fastcgi_read_timeout 150;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Then, we restart PHP-FPM and Nginx.

service php-fpm restart
service nginx restart

This removes the 504 error from the website and it starts working correctly.


[Getting 504 timeout error in Nginx? We are here to fix it.]



In short, a “504 timeout Nginx” error is one of the HTTP status code that a server sends back if the underlying request is not completed. Today, we saw how our Support Engineers fixed “504 timeout error” in Nginx.

Leave a Comment

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

Social Share


Cheapest Web Hosting

Fasters Web Hosting Promo
Scroll to Top

Launch your Website at RS599

Create a professional website yourself with our domain hosting combo. Get Extra benefits at this Year end Sale with 10% OFF and Enjoy Amazing Deels on Shared Hosting!

Starting at Only RS599/Year

Year End Sale


Use Code STARTBIZ at Checkout.

Create an earning opportunity with A Web Hosting Business

Become reseller and start reselling domains, web hosting, ssl certificates and More.

45% OFF

Starting at RS399/Month


Use coupon: at the checkout.