Cause analysis:
To solve these two problems is actually need to think about, in general, Nginx 502 Bad Gateway and php-fpm.conf settings,
Nginx 504 Gateway Time-out is related to nginx. conf settings.
The php-fpm.conf has two crucial parameters: "max_children" and "request_terminate_timeout", but this value is not generic and needs to be calculated on its own.
Method 1: temporary solution:
To sum up, the temporary solutions for Nginx prompting 502 and 504 errors are as follows:
1. Adjust the settings of the php-fpm.conf:
The code is as follows: |
Copy code |
<Value name = "max_children"> 32 </value> <Value name = "request_terminate_timeout"> 30 s </value> |
2. Adjust the nginx. conf settings:
The code is as follows: |
Copy code |
Fastcgi_connect_timeout 600; Fastcgi_send_timeout 600; Fastcgi_read_timeout 600; Fastcgi_buffer_size 256 k; Fastcgi_buffers' 16 256 k; Fastcgi_busy_buffers_size 512 k; Fastcgi_temp_file_write_size 512 k; |
Method 2: regularly restart php-fpm:
The solution shown in Heading 3 can only temporarily solve the problem, and if the website traffic is indeed very large, nginx + FastCGI can only achieve good results in handling high concurrency in an instant or a short period of time. Therefore, the only ultimate solution currently is to regularly and smoothly restart php-cgi.
The specific configuration is as follows:
1. Write a very simple script:
The code is as follows: |
Copy code |
# Vi/home/www.scripts/php-fpm.sh The content is as follows: #! /Bin/bash # This script run at */1 /Usr/local/php/sbin/php-fpm reload |
2. Add the script to the scheduled task:
The code is as follows: |
Copy code |
# Crontab-e The content is as follows: */1 ***/home/www/scripts/php-fpm.sh |
Note: For the sake of convenience, you can directly write the php-fpm smooth restart command in crontab without writing a script.