Do site students often find some Nginx server access when prompted 504 Gateway time-out error, generally by the Nginx default fastcgi process response slow, but there are other situations, here I summed up some solutions for your reference.
Method/Step
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.
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.
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.
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.
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.
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!
How to troubleshoot "504 Gateway time-out" error