|
In the past few days, there have been many problems with Nginx 502 on the web, and I thought it was a problem with Nginx like many people at first.
The web uses the architecture of nginx+php, and the website has not been online for a long time, so the optimization is basically just some initial configuration.
Checking php-fpm.log found warnings, which basically coincided with the time the website was suspended. I'll start here.
I also looked for some documentation at first, but there was still a problem the next day. Later, I checked the configuration file and translated it (Baidu), and the English foundation was not good. The PM module is similar to Apache's module, which is static and dynamic.
Many of the adjustments mentioned on the Internet are mostly based on dynamics, but they do not say how to define this module. So everyone should take a closer look at the configuration file when using dynamic and static pm = static
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 300
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
;pm.start_servers = 50
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
;pm.min_spare_servers = 20
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
;pm.max_spare_servers = 500
; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
pm.process_idle_timeout = 10s;
; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 10240
The red field is the way to define it, and then set the parameters according to the server situation
If you use the static pm.max_children parameter, it will work, the rest will not. The dynamics are the opposite.
2G memory pm.max_children is about 50 turned on, which is necessary to adjust according to the actual situation.
If there is any shortcoming, I would like you to give your opinions, 502 solutions.
|