In this tutorial, we will show you how to fix 504 gateway time-out on the Nginx web server on the Linux server. If you run an Nginx web server you may have already encountered the annoying 504 Gateway Time-out errors. This is a pretty common error, are generated most probably by the PHP max execution time limit, or by the FastCGI read timeout settings.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you through the step by step installation to fix Nginx 504 gateway timeout on the Nginx webserver.
Fix 504 Gateway Time-out on Nginx
Changes in php.ini
Try raising the
max_execution_time setting in php.ini file (CentOS path is
Changes in PHP-FPM
Try raising the
request_terminate_timeout setting in the php.ini file (CentOS path is
Changes in Nginx Config
Finally, add the fastcgi_read_timeout variable inside our Nginx virtual host configuration:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Reload PHP-FPM and Nginx
For Nginx as Proxy for Apache web server, this is what you have to try to fix the 504 Gateway Timeout error:
Add the following variables to nginx.conf file:
Once complete, simply reload Nginx:
Congratulations! You have successfully fixed error Nginx 504 gateway time out. Thanks for using this tutorial to fix 504 gateway timeout errors in the Linux system. For additional help or useful information, we recommend you to check the official Nginx web site.