吾知网

标题: Nginx 502 Bad Gateway [打印本页]

作者: jekeyhui99    时间: 2015-11-14 12:10
标题: Nginx 502 Bad Gateway
试用Nginx + PHP FastCGI 做WEB服务器,运行了几个月的时间,烦恼的是经常碰到Nginx 502 Bad Gateway 这个问题。
参考了很多修改办法,这个502的问题一直存在,今天打算重装PHP FastCGI到PHP的安装目录里一看,发现PHP的日志文件已经有几十M的大小,打开一看,结果基本全部都是一下的错误:

Jan 11 08:54:01.164292 [NOTICE] fpm_children_make(), line 352: child 10088 (pool default) started
Jan 11 08:54:01.164325 [WARNING] fpm_children_bury(), line 215: child 7985 (pool default) exited on signal 15 SIGTERM after 63.778601 seconds from start
Jan 11 08:54:01.165485 [NOTICE] fpm_children_make(), line 352: child 10089 (pool default) started
Jan 11 08:54:01.165514 [WARNING] fpm_children_bury(), line 215: child 7999 (pool default) exited on signal 15 SIGTERM after 60.297326 seconds from start
Jan 11 08:54:01.166696 [NOTICE] fpm_children_make(), line 352: child 10090 (pool default) started
Jan 11 08:54:01.166727 [WARNING] fpm_children_bury(), line 215: child 8000 (pool default) exited on signal 15 SIGTERM after 60.296946 seconds from start
Jan 11 08:54:01.167855 [NOTICE] fpm_children_make(), line 352: child 10091 (pool default) started
Jan 12 04:00:50.443884 [NOTICE] fpm_children_make(), line 352: child 10127 (pool default) started
Jan 12 04:00:50.443917 [NOTICE] fpm_event_loop(), line 107: libevent: entering main loop
Jan 12 12:05:08.425141 [WARNING] fpm_request_check_timed_out(), line 158: child 10120, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.051306 sec), terminating



查过网上的资源,基本都是认为是php线程打开文件句柄受限导致的错误。具体的解决的办法如下:

1、提升服务器的文件句柄打开打开
/etc/security/limits.conf : (增加)
*    soft    nofile    51200
*    hard    nofile    51200
# vi /etc/security/limits.conf 加上
* soft nofile 51200
* hard nofile 51200


2、提升nginx的进程文件打开数

nginx.conf : worker_rlimit_nofile 51200;

3、修改php-fpm.conf文件,主要需要修改2处

命令 ulimit -n 查看限制的打开文件数,php-fpm.conf 中的选项rlimit_files 确保和此数值一致。

<value name="max_requests">10240</value>

<value name="rlimit_files">51200</value>

4、
# vi /etc/sysctl.conf
底部添加
fs.file-max=51200


完成以上修改,重启PHP,警告信息再也没了。

世界从此安宁,502 Bad Gateway 没有了。







欢迎光临 吾知网 (http://175999.com/bbs/) Powered by Discuz! X3.2