“504 Gateway Timeout” error is a very common issue when using Nginx with PHP-FPM. Usually, that means that it took PHP-FPM longer to generate the response, than Nginx was willing to wait for. A few possible reasons for this are:
- Nginx timeout configuration uses very small values (expecting the responses to be unrealistically fast).
- The web server is overloaded and takes longer than it should to process requests.
- The PHP application is slow (maybe due to database behind it being or slow).
There is plenty advice online on how to troubleshoot and sort these issues. But when it comes down to increasing the timeouts, I found such advice to be scattered, incomplete, and often outdated. This page, however, has a good collection of tweaks. They are:
- Increase PHP maximum execution time in /etc/php.ini: max_execution_time = 300
- Increase PHP-FPM request terminate timeout in the pool configuration (/etc/php-fpm.d/www.conf): request_terminate_timeout = 300
- Increase Nginx FastCGI read timeout (in /etc/nginx/nginx.conf): fastcgi_read_timeout 300;
Also, see this Stack Overflow thread for more suggestions.
P.S.: while you are sorting out your HTTP errors, have a quick look at HTTP Status Dogs, which I blogged about a while back.
7 thoughts on “504 Gateway Timeout error on Nginx + FastCGI (php-fpm)”
504 Gateway Timeout error on Nginx + FastCGI (php-fpm) #SysAdmin #DevOps #hosting #Nginx… https://t.co/r2PhIv4GGv https://t.co/3COCNgFYgo
504 Gateway Timeout error on Nginx + FastCGI (php-fpm) | Blog of Leonid Mamchenkov: #http, #503, #nginx, #fas… https://t.co/cvYf8k3SBA
the same article in 2013
Yes, and I’m linking to it from my post :)