在谷歌云上获得502糟糕的网关

时间:2016-04-01 15:26:42

标签: php mysql nginx google-compute-engine google-cloud-platform

我拥有一个n1-highcpu-16(16个vCPU,14.4 GB内存)。我有Bitnami NGINX设置。

当我在网站上有大约400-600人时,它有时会提供502个坏网关。我正在运行机器人,所以它往往会给我带来很大的错误。当站点收到大约50-100个对PHP文件执行一个SQL连接的请求时,就会发生这种情况。 之后,在我的网站上出现502错误的网关错误。

有没有解决方法如何解决?

我的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

1 个答案:

答案 0 :(得分:0)

您确定这是SQL连接的问题吗?由于您的pm.max_children设置为50,如果所有50个线程都在使用中,则会引发 502 Bad Gateway 错误。您应该尝试启动其他服务器以处理更多请求。

或者,尝试提升和降低pm.max_children并查看这是否会影响数字,并帮助得出结论。