Fix error: 504 Gateway Time-out

504 Gateway Time-out

It’s very common to see a 504 Gateway Time-out with Nginx. This error could be a number of reasons on the backend connection that is serving content.

For Nginx + FastCGI (php-fpm), you should try to tweak Nginx configuration.

Edit file ‘/etc/php.ini‘ and try to raise the ‘max_execution_time‘ like so:

max_execution_time = 300

Then add ‘fastcgi_read_timeout‘ variable inside your Nginx vhost configuration like so:

# use fastcgi for all php files
location ~ \.php$ {
    #try_files       $uri =404;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include         fastcgi_params;
    fastcgi_read_timeout 300;
}

Then reload Nginx:

service nginx reload