In general, this situation may be caused by the small buffer of nginx's default fastcgi Process response, which will cause the fastcgi process to be suspended. If your fastcgi service does not handle this suspension well, in the end, 504 Gateway Time-out may occur.
Today's websites, especially some forums, have a lot of replies and a lot of content. One page even has hundreds of K
The default fastcgi Process response buffer is 8 kB. We can set a large value.
In nginx. conf, add:
Fastcgi_buffers 8 128 k
This indicates that the fastcgi buffer is set to 8*128 k.
Of course, if you are performing an immediate operation, you may need to increase the value of the nginx timeout parameter, for example, to 60 seconds:
Send_timeout 60;
I just adjusted the two parameters, and the result is that the timeout value is not displayed. It can be said that the effect is good.
Another article
First, modify the configuration of php-fpm:
Change max_children from the previous 10 to the current 30, so that sufficient php-cgi processes can be used;
Change request_terminate_timeout from the previous 0 s to 60 s, so that the timeout time for the php-cgi process to process the script is 60 seconds, which can prevent the process from being suspended and improve the utilization efficiency.
Then, modify several nginx configuration items to reduce the number of FastCGI requests and try to keep buffers unchanged:
Change fastcgi_buffers from 4 64 k to 2 256 k;
Fastcgi_buffer_size is changed from 64 k to 128 K;
Fastcgi_busy_buffers_size is changed from 128 K to 256 K;
Fastcgi_temp_file_write_size is changed from 128 K to 256 K.
Okay, reload the configuration of php-fpm and nginx, and test again. So far, No 504 Gateway Time-out has been found in two weeks.
In addition, the default static processing method of php-fpm will make the php-cgi process occupy the memory for a long time and cannot be released, which is also one of the causes of nginx errors, therefore, you can change the php-fpm processing method to the apache mode.
Apache-like