你好,游客 登录 注册 搜索
背景:
阅读新闻

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

[日期:2013-01-25] 来源:Linux社区  作者:5921271 [字体: ]

这几天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解决办法。

linux
相关资讯       Nginx  Nginx 502  Nginx调优 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款