Nginx – 504 gateway timeout after loading several php pages

nginxphp-fpm

I have found that after requesting several php pages in succesion, the page load time seems to slow down, before eventually not loading, and giving 504.

I can't find any relevant errors except this in the php5-fpm log

[13-Dec-2013 17:53:41] WARNING: [pool web36] child 6797 exited on signal 9 (SIGKILL) after 3165.155870 seconds from start
[13-Dec-2013 17:53:41] NOTICE: [pool web36] child 8078 started
[13-Dec-2013 17:55:15] WARNING: [pool web36] child 7848 exited on signal 9 (SIGKILL) after 633.767987 seconds from start
[13-Dec-2013 17:55:15] NOTICE: [pool web36] child 8100 started
[13-Dec-2013 17:56:19] WARNING: [pool web36] child 7914 exited on signal 11 (SIGSEGV) after 455.341786 seconds from start

How should I troubleshoot from here on in?

Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-31-generic x86_64)
PHP 5.3.10-1ubuntu3.5 with Suhosin-Patch
nginx/1.1.19

Best Answer

Nginx will throw a 504 gateway time-out when your php script takes too much time (longer than 60 seconds).

It's possible to optimize php script or increase nginx fastcgi_read_timeout param (http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html).

Example:

location ~ /(index).php {
    fastcgi_read_timeout 3m;

    fastcgi_pass   127.0.0.1:8888;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  PATH_INFO        $fastcgi_script_name;
    include fastcgi_params; 
}