My friend said that the error message 504 Gateway Time-out has nothing to do with nginx itself. We can solve this problem by adjusting the fastcgi configuration parameters.
.
Modify the php-fpm configuration file:
1. Modify max_children according to the system to ensure that there are sufficient php-cgi processes available;
Modify the php-fpm configuration file to increase the number of php-cgi processes
Modify the number of php-cgi processes:
The code is as follows: |
Copy code |
6/usr/local/php/etc/php-fpm.conf Find: <Value name = "max_children"> 5 </value> |
Find the number of PHP processes modified according to your memory capacity. Generally, 6 PHP processes are enabled for 128 of the memory, and 16 PHP processes are enabled for 256 of the memory. This ensures high concurrency in PHP.
No 502 error. A process occupies 12M-20M, and the specific number of opened processes depends on the memory size.
Max_children is used to set the number of FastCGI processes. According to official recommendations, for servers with less than 2 GB of memory, only 64 processes can be enabled, with more than 4 GB of memory
The server can start 200 processes.
2. Change request_terminate_timeout 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.
To improve utilization efficiency.
Modify the nginx. conf file as follows:
The code is as follows: |
Copy code |
Fastcgi_connect_timeout 60; Fastcgi_send_timeout 180; Fastcgi_read_timeout 180; Fastcgi_buffers' 4 256 k; Fastcgi_buffer_size 128 k; Fastcgi_busy_buffers_size 256 k; Fastcgi_temp_file_write_size 256 k; Fastcgi_intercept_errors on; |
Then restart your server/etc/init. d/php-fpm restart to solve the problem.