Cause
1. PHP FastCGI Process count is insufficient
When the number of concurrent accesses to the website is huge, the number of php fastcgi processes is not guaranteed, because cgi works in a single thread and multiple processes, that is to say, cgi needs to process a page before continuing the next page. If the number of processes is not enough, when the access is huge, cgi processes the previous requests in line, and the subsequent requests will only be abandoned. In this case, nginx may encounter a 502 error from time to time.
2. PHP FastCGI memory is insufficient
When nginx returns a static page, this problem will not occur, because nginx directly returns a static page without php cgi processing. However, when a webpage needs to handle a large number of php complex operations, such as api collection or page collection, php requires a high level, if the configured memory is too small, it will easily cause php to crash.
Solution
Because I restarted the server several times before.
The code is as follows: |
Copy code |
#/Etc/init. d/php-fpm start Starting php-fpm done |
The above is my solution, but I personally think it is not safe to find it again.
Script execution time timeout
If the script does not return after a long wait for some reason, the new request cannot be processed, you can adjust the following configurations as appropriate.
Nginx. conf mainly includes the following:
The code is as follows: |
Copy code |
Fastcgi_connect_timeout 300; Fastcgi_send_timeout 300; Fastcgi_read_timeout 300; |
If the php-fpm.conf is as follows
The code is as follows: |
Copy code |
Request_terminate_timeout = 10 s |