504 Gateway Time-out usando Nginx

It is very common to see a 504 Gateway Time-out using Nginx webserver. This timeout error is generated often by a number of reasons on the backend connection that is serving content. To fix it, you will have to figure out what configuration are you using.

For Nginx + FastCGI (php-fpm), you should try to tweak nginx configuration in this way-:

Try raising max_execution_time setting in php.ini file (Ubuntu path is /etc/php5/fpm/php.ini):

max_execution_time = 300

But, you should also change set request_terminate_timeout parameter (commented by default) at www.conf file from PHP-FPM:

pico -w /etc/php-fpm.d/www.conf

Then set the variable to the same value as max_execution_time:

request_terminate_timeout = 300

Now let’s add  fastcgi_read_timeout variable inside our Nginx virtual host configuration:

location ~ \.php$ {
root /var/www/sites/nginxtips.com;
try_files $uri =404;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 300;

Then restart nginx:

service nginx reload