我拥有一个 n1-highcpu-16(16 个 vCPU,14.4 GB 内存)。我有一个 Bitnami NGINX 设置。
当我的网站上有大约 400-600 人时,它有时会给出 502 错误网关。我用它来运行机器人,所以它往往会为我犯大错误。当站点收到大约 50-100 个对执行一个 SQL 连接的 PHP 文件的请求时,就会发生这种情况。 之后,在我的网站上出现了 502 bad gateway 错误。
有什么解决办法吗?
我的 PHP 设置:
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=50
; 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=5
; 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=5
; 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=30
; 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 = 5000
最佳答案
您确定这是 SQL 连接的问题吗?因为您的 pm.max_children
设置为 50
,如果所有 50 个线程都在使用中,将抛出 502 Bad Gateway 错误。您应该尝试启动更多服务器来处理更多请求。
或者,尝试升高和降低 pm.max_children
,看看这是否会影响数字,并有助于得出结论。
关于php - 在谷歌云上获取 502 错误网关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36360144/