架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6977|回复: 0

[Web] Nginx php-fpm出现502解决办法和调优心得

[复制链接]
发表于 2014-11-6 09:34:04 | 显示全部楼层 |阅读模式
这几天web经常出现Nginx 502的问题,先开始也像很多人一样认为是Nginx的问题,从网上查了查原来是php-fpm在作怪。

web使用的是nginx+php的架构,网站上线还没多久,所以优化方面基本只是做了些初始的配置。

查看php-fpm.log发现有警告,这些警告和网站的挂了个时间基本吻合。我就从这里开始入手。

先开始也是找了些文档,但是第二天还是出现问题。后来查看配置文件并翻译了下(百度),英文底子不好。pm模块类似apache的模块,是分静态和动态的。

网上说的很多调整都是基于动态居多,但是并没说么定义这个模块。所以大家用动态和静态还是要仔细看看配置文件
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



红色字段就是定义方式的,定义好这个再去根据服务器情况设置参数

假如使用静态 pm.max_children这个参数会起作用,其余不会。动态反之。

2G内存pm.max_children大概开启50左右,按照实际情况来调优,这个是很必要的。

如果哪里有不足希望大家提意见,502解决办法。





上一篇:《猩球崛起2:黎明之战》2014豆瓣评分:7.6
下一篇:php-fpm.conf两个至关重要的参数
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|手机版|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2024-4-29 06:44

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表