您的位置 首页 php

错误解决:Nginx php-fpm 502 bad gateways

环境:

Ubuntu 16.04.2

nginx version: nginx/1.10.3 (Ubuntu)

php-fpm version: php-fpm/5.6

php-fpm错误日志

WARNING: [pool www] server reached pm.max_children setting (5), consider raising it

Nginx错误日志

eader from upstream, client: xxx.xxx.xxxx.xxx, server: xxx.domain.com, request : “GET /index.php/1/2/test.html HTTP/1.0”, upstream: “fastcgi://unix:/run/php/php5.6-fpm.sock:”, host: “xxx.domain.com”, referrer: “”

从Nginx日志里面很容易看出来,是php-fpm出了问题,重启php-fpm后网站恢复正常。php-fpm日志里面给出了详细的错误提示,子进程数已经达到设置的最大值。

解决方案

/etc/php/5.6/fpm/php-fpm.conf

/etc/php/5.6/fpm/pool.d/www.conf

定位至配置文件,查找pm.max_children项 (5.6版本在www.conf中)

pm = dynamic #对于专用服务器,pm可以设置为 static

#如何控制子进程,选项有static和dynamic。如果选择static,则由pm.max_children指定固定的子进程数。如果选择dynamic,则由下开 参数决定:

pm.max_children #,子进程最大数

pm.start_servers #,启动时的进程数

pm.min_spare_servers #,保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程

pm.max_spare_servers #,保证空闲进程数最大值,如果空闲进程大于此值,此进行清理

pm:表示使用那种方式,有两个值可以选择,就是static(静态)或者dynamic(动态)。

在更老一些的版本中,dynamic被称作apache-like。这个要注意看配置文件的说明。

下面4个参数的意思分别为:

pm.max_children:静态方式下开启的php-fpm进程数量

pm.start_servers:动态方式下的起始php-fpm进程数量

pm.min_spare_servers:动态方式下的最小php-fpm进程数

pm.max_spare_servers:动态方式下的最大php-fpm进程数量

区别

如果dm设置为 static,那么其实只有pm.max_children这个参数生效。系统会开启设置数量的php-fpm进程。

如果dm设置为 dynamic,那么pm.max_children参数失效,后面3个参数生效。

系统会在php-fpm运行开始 的时候启动pm.start_servers个php-fpm进程,然后根据系统的需求动态在pm.min_spare_servers和pm.max_spare_servers之间调整php-fpm进程数

关于数量的计算方法可以通过memory_get_peak_usage(true)这个函数获得内存峰值,以此作为单个请求的程序内存消耗消耗量,并考虑进php-fpm本身的基础内存消耗,可以得到一个近似的单进程内存消耗量。

文章来源:智云一二三科技

文章标题:错误解决:Nginx php-fpm 502 bad gateways

文章地址:https://www.zhihuclub.com/80093.shtml

关于作者: 智云科技

热门文章

评论已关闭

3条评论

  1. Unquestionably believe that which you said. Your favorite justification appeared to be on the net the easiest thing to be aware of.

    I say to you, I definitely get irked while people think about worries that they just don’t know about.

    You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal.
    Will probably be back to get more. Thanks

  2. I am really loving the theme/design of your website. Do you ever
    run into any internet browser compatibility issues? A handful of my blog visitors have complained about my site not operating
    correctly in Explorer but looks great in Chrome. Do
    you have any tips to help fix this problem?

  3. Everything is very open with a clear explanation of the challenges.
    It was definitely informative. Your site is very helpful.
    Many thanks for sharing!

网站地图