Modify Nginx.conf:
fastcgi_connect_timeout;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 128k;
Fastcgi_buffers 8 128k;
Fastcgi_busy_buffers_size 128k;
Fastcgi_temp_file_write_size 256k;
After the restart nginx,504 gateway timeout is mitigated, no similar situation occurs.
Situation one: Due to nginx default fastcgi process response buffer too small caused
This situation causes the FASTCGI process to be suspended, and if the FASTCGI service is not well-handled, it may prompt "504 Gateway time-out" error.
2
Situation One solution:
The default fastcgi process response buffer is 8K, we can set a larger, in nginx.conf, join: Fastcgi_buffers 8 128k
This indicates that the fastcgi buffer is set to a size of 8 128k in space.
3
Situation one solution (improvement):
After the above method is modified, if the problem still occurs, we can continue to modify the Nginx timeout parameter, the parameter is a bit larger, such as set to 60 seconds:
Send_timeout 60;
After the adjustment of these two parameters, the results did not prompt "504 Gateway time-out" error, indicating that the effect is quite good, the problem is basically solved.
4
Scenario Two: Configuration issues for the PHP environment
Here we need to make configuration changes to PHP-FPM and Nginx. Because of this scenario, the "504 Gateway time-out" error message appears.
5
Situation two solutions (PHP-FPM configuration Modification):
Change the Max_children from the previous 10 to 30, so the operation is to ensure that there is sufficient php-cgi process can be used.
Change the request_terminate_timeout from the previous 0 seconds to 60 seconds, which increases the time-out of the PHP-CGI process processing script to 60 seconds, preventing the process from being suspended to improve utilization efficiency.
6
Scenario Two solutions (Nginx configuration Modification):
In order to reduce the number of FASTCGI requests, as far as possible to maintain buffers unchanged, we want to change the Nginx several configuration items, as follows:
Change the fastcgi_buffers from 4 to 64k to 2 256k;
Change the fastcgi_buffer_size from 64k to 128k;
Change the fastcgi_busy_buffers_size from 128k to 256k;
Change the fastcgi_temp_file_write_size from 128k to 256k.
7
When the two solutions are modified, we need to reload the PHP-FPM and Nginx configurations before testing. Then did not find "504 Gateway time-out" error, the effect is also good!
504 Gateway Time-out