Solution to php504 error: 1. Increase the buffer size of the fastcgi process response; 2. Change the php environment configuration and increase the timeout of the php-cgi process processing script; 3. Change the processing method of php-fpm Change to apache mode.
The solution is as follows:
Scenario 1:
Due to the buffer response of nginx’s default fastcgi process Error caused by being too small
Solution:
Generally, the default fastcgi process response buffer is 8K. In this case, you can set it larger. In nginx.conf, add: fastcgi_buffers 8 128k, which means setting the fastcgi buffer to 8 blocks of 128k space.
Of course, if you are performing a certain real-time operation, you may need to increase the timeout parameter of nginx, for example, set it to 60 seconds: send_timeout 60; after adjusting these two parameters, generally you will no longer be prompted with " 504 Gateway Time-out" error, the problem is basically solved.
Scenario 2:
Configuration issues of PHP environment
Sometimes the website needs to modify the configuration of php-fpm and nginx. Because in this case, the "504 Gateway Time-out" error message will also appear. At this time, the meaning of Nginx 504 Gateway Time-out is that the requested gateway has not been requested. Simply put, it means that the executable PHP-CGI has not been requested.
Solution:
Just change a few configurations of php-fpm:
Change max_children from the previous 10 to the current 30, so as to ensure that there are enough The php-cgi process can be used;
Change request_terminate_timeout from the previous 0s to 60s, 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 utilization efficiency. .
Then change several configuration items of nginx to reduce the number of FastCGI requests and try to keep the buffers unchanged:
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;
fastcgi_temp_file_write_size changed from 128K to 256K.
Reload the configuration of php-fpm and nginx and test again. If the "504 Gateway Time-out" error does not appear, the problem is solved.
Scenario 3:
The default static processing method of php-fpm will cause the php-cgi process to occupy memory for a long time and cannot be released, resulting in a 504 error.
Solution:
Change the processing method of php-fpm to apache mode.
If you want to learn more related knowledge, please visit php Chinese website.
The above is the detailed content of How to solve php504 error. For more information, please follow other related articles on the PHP Chinese website!