In general, this situation may be due to the Nginx default fastcgi process response buffer too small, which will cause the fastcgi process to be suspended, if your fastcgi service to this suspend processing is not good, then it is very likely to cause the 504 Gateway Time-out
Now the site, especially some forums have a lot of replies and a lot of content, a page even has hundreds of K
The default fastcgi process response buffer is 8K and we can set the larger point
In nginx.conf, join:
Fastcgi_buffers 8 128k
This means that the fastcgi buffer is set to 8x128k
Of course, if you are doing an immediate operation, you may need to nginx the timeout parameter, for example, set to 60 seconds:
Send_timeout 60;
I just adjusted these two parameters, the result is no longer show that timeout, you can say that the effect is good
Another article
The first is to change several configurations of the PHP-FPM:
Change the Max_children from the previous 10 to the current 30, so that sufficient php-cgi process can be used;
Change the request_terminate_timeout from the previous 0s to 60s, so that the php-cgi process script timeout is 60 seconds, preventing the process from being suspended and increasing utilization efficiency.
Then change the nginx of several configuration items, reduce the number of FASTCGI requests, as far as possible to maintain buffers unchanged:
The fastcgi_buffers is changed from 4 64k to 2 256k;
Fastcgi_buffer_size changed from 64k to 128K;
Fastcgi_busy_buffers_size changed from 128K to 256K;
The fastcgi_temp_file_write_size is changed from 128K to 256K.
OK, reload php-fpm and Nginx configuration, again test, so far two weeks time no longer appear 504 Gateway time-out situation, is to achieve the effect.
In addition, the default static processing of PHP-FPM can make the process of php-cgi to occupy memory for a long time and cannot be released, which is also one of the causes of Nginx error, so can change the PHP-FPM processing mode to Apache mode.
Apache-like