试用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
Jan 12 12:05:08.929741 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 12 12:05:09.137341 [WARNING] fpm_children_bury(), line 215: child 10120 (pool default) exited on signal 15 SIGTERM after 29058.697774 seconds from start
Jan 13 01:16:43.058020 [NOTICE] fpm_pctl_exit(), line 81: exiting, bye-bye!
Jan 13 01:16:46.236418 [NOTICE] fpm_unix_init_main(), line 284: getrlimit(nofile): max:52000, cur:52000
Jan 13 01:16:46.236655 [NOTICE] fpm_event_init_main(), line 88: libevent: using epoll
Jan 13 01:16:46.610883 [NOTICE] fpm_init(), line 52: fpm is running, pid 14095
Jan 13 01:16:46.612247 [NOTICE] fpm_children_make(), line 352: child 14103 (pool default) started
Jan 13 01:16:46.613190 [NOTICE] fpm_children_make(), line 352: child 14104 (pool default) started
Jan 13 01:16:46.614159 [NOTICE] fpm_children_make(), line 352: child 14105 (pool default) started
Jan 13 01:16:46.615627 [NOTICE] fpm_children_make(), line 352: child 14106 (pool default) started
Jan 13 01:16:46.616362 [NOTICE] fpm_children_make(), line 352: child 14107 (pool default) started
Jan 13 01:16:46.617045 [NOTICE] fpm_children_make(), line 352: child 14108 (pool default) started
Jan 13 01:17:33.243576 [WARNING] fpm_request_check_timed_out(), line 158: child 14103, script '/home/htdocs/www/index.php' (pool default) execution timed out (34.024787 sec), terminating
Jan 13 01:17:33.244174 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 13 01:17:33.244228 [WARNING] fpm_children_bury(), line 215: child 14103 (pool default) exited on signal 15 SIGTERM after 46.632004 seconds from start
Jan 13 01:17:33.250331 [NOTICE] fpm_children_make(), line 352: child 15488 (pool default) started
Jan 13 01:27:23.052006 [WARNING] fpm_request_check_timed_out(), line 158: child 14106, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.035273 sec), terminating
Jan 13 01:27:23.902504 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 13 01:27:23.939140 [WARNING] fpm_children_bury(), line 215: child 14106 (pool default) exited on signal 15 SIGTERM after 637.323523 seconds from start
Jan 13 01:27:23.940355 [NOTICE] fpm_children_make(), line 352: child 1658 (pool default) started
Jan 13 01:27:34.398321 [WARNING] fpm_request_check_timed_out(), line 158: child 14107, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.076368 sec), terminating
Jan 13 01:27:34.529319 [WARNING] fpm_request_check_timed_out(), line 158: child 14107, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.207367 sec), terminating
Jan 13 08:09:44.189826 [NOTICE] fpm_children_make(), line 352: child 30465 (pool default) started
Jan 13 08:10:08.045110 [NOTICE] fpm_children_make(), line 352: child 31815 (pool default) started
Jan 13 09:15:20.604471 [WARNING] fpm_request_check_timed_out(), line 158: child 31813, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.006392 sec), terminating
Jan 13 09:15:21.615288 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 13 09:15:21.615347 [WARNING] fpm_children_bury(), line 215: child 31813 (pool default) exited on signal 15 SIGTERM after 3913.810239 seconds from start
Jan 13 11:06:18.645301 [WARNING] fpm_request_check_timed_out(), line 158: child 1905, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.019438 sec), terminating
Jan 13 11:06:19.189703 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 13 11:06:19.262665 [WARNING] fpm_children_bury(), line 215: child 1905 (pool default) exited on signal 15 SIGTERM after 34719.959291 seconds from start
Jan 13 11:06:19.264634 [NOTICE] fpm_children_make(), line 352: child 23748 (pool default) started
Jan 13 22:05:29.623956 [WARNING] fpm_request_check_timed_out(), line 158: child 9412, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.038766 sec), terminating
Jan 13 22:05:29.940748 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 13 22:05:30.118247 [WARNING] fpm_children_bury(), line 215: child 9412 (pool default) exited on signal 15 SIGTERM after 41228.780226 seconds from start
Jan 13 22:05:30.120231 [NOTICE] fpm_children_make(), line 352: child 30489 (pool default) started
Jan 13 22:11:15.155278 [WARNING] fpm_request_check_timed_out(), line 158: child 12118, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.027702 sec), terminating
Jan 13 22:11:20.906721 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 13 22:11:22.375915 [WARNING] fpm_children_bury(), line 215: child 12118 (pool default) exited on signal 15 SIGTERM after 41371.257053 seconds from start
Jan 13 22:11:22.377362 [NOTICE] fpm_children_make(), line 352: child 15899 (pool default) started
Jan 13 22:16:30.459322 [NOTICE] fpm_got_signal(), line 56: received SIGTERM
Jan 13 22:16:30.600664 [NOTICE] fpm_pctl(), line 256: switching to 'terminating' state
Jan 13 22:16:30.601166 [NOTICE] fpm_pctl_kill_all(), line 172: sending signal 15 SIGTERM to child 15899 (pool default)
Jan 13 22:16:30.601439 [NOTICE] fpm_pctl_kill_all(), line 172: sending signal 15 SIGTERM to child 30489 (pool default)
Jan 13 22:16:30.604748 [NOTICE] fpm_pctl_kill_all(), line 172: sending signal 15 SIGTERM to child 23748 (pool default)
Jan 13 22:16:30.608901 [NOTICE] fpm_pctl_kill_all(), line 172: sending signal 15 SIGTERM to child 32323 (pool default)
Jan 13 22:16:30.652696 [WARNING] fpm_children_bury(), line 215: child 3515 (pool default) exited on signal 15 SIGTERM after 53860.208516 seconds from start
Jan 13 22:16:30.652735 [WARNING] fpm_children_bury(), line 215: child 30465 (pool default) exited on signal 15 SIGTERM after 50806.462919 seconds from start
Jan 13 22:16:30.652773 [WARNING] fpm_children_bury(), line 215: child 31812 (pool default) exited on signal 15 SIGTERM after 50782.848515 seconds from start
Jan 13 22:16:30.683815 [WARNING] fpm_children_bury(), line 215: child 31815 (pool default) exited on signal 15 SIGTERM after 50782.638716 seconds from start
Jan 13 22:16:30.683868 [WARNING] fpm_children_bury(), line 215: child 32323 (pool default) exited on signal 15 SIGTERM after 46869.067366 seconds from start
Jan 13 22:16:30.683907 [WARNING] fpm_children_bury(), line 215: child 23748 (pool default) exited on signal 15 SIGTERM after 40211.419289 seconds from start
Jan 13 22:16:30.683947 [WARNING] fpm_children_bury(), line 215: child 30489 (pool default) exited on signal 15 SIGTERM after 660.563729 seconds from start
Jan 13 22:16:30.683987 [WARNING] fpm_children_bury(), line 215: child 15899 (pool default) exited on signal 15 SIGTERM after 308.306637 seconds from start
Jan 13 22:16:30.684008 [NOTICE] fpm_pctl_exit(), line 81: exiting, bye-bye!
Jan 13 22:16:38.214052 [NOTICE] fpm_unix_init_main(), line 284: getrlimit(nofile): max:52000, cur:52000
Jan 13 22:16:38.214303 [NOTICE] fpm_event_init_main(), line 88: libevent: using epoll
Jan 13 22:16:38.214366 [NOTICE] fpm_init(), line 52: fpm is running, pid 22086
Jan 13 22:16:38.215305 [NOTICE] fpm_children_make(), line 352: child 22089 (pool default) started
Jan 13 22:16:38.216038 [NOTICE] fpm_children_make(), line 352: child 22090 (pool default) started
Jan 13 22:16:38.216738 [NOTICE] fpm_children_make(), line 352: child 22091 (pool default) started
Jan 13 22:16:38.217453 [NOTICE] fpm_children_make(), line 352: child 22092 (pool default) started
Jan 13 22:16:38.218000 [NOTICE] fpm_children_make(), line 352: child 22093 (pool default) started
Jan 13 22:16:38.218890 [NOTICE] fpm_children_make(), line 352: child 22094 (pool default) started
Jan 13 22:16:38.219617 [NOTICE] fpm_children_make(), line 352: child 22095 (pool default) started
Jan 13 22:16:38.225531 [NOTICE] fpm_event_loop(), line 107: libevent: entering main loop
Jan 13 22:17:27.370069 [WARNING] fpm_request_check_timed_out(), line 158: child 22089, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.038985 sec), terminating
Jan 13 22:17:27.468485 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 13 22:17:27.468544 [WARNING] fpm_children_bury(), line 215: child 22089 (pool default) exited on signal 15 SIGTERM after 49.253256 seconds from start
Jan 13 22:17:27.469667 [NOTICE] fpm_children_make(), line 352: child 24464 (pool default) started
Jan 13 22:19:31.308673 [WARNING] fpm_request_check_timed_out(), line 158: child 22091, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.017504 sec), terminating
Jan 13 22:19:31.391669 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 13 22:19:31.391726 [WARNING] fpm_children_bury(), line 215: child 22091 (pool default) exited on signal 15 SIGTERM after 173.174998 seconds from start
Jan 13 22:19:31.392806 [NOTICE] fpm_children_make(), line 352: child 26115 (pool default) started
Jan 13 22:19:54.583311 [WARNING] fpm_request_check_timed_out(), line 158: child 22092, script '/home/htdocs/blog/index.php' (pool default) execution timed out (30.059096 sec), terminating
Jan 13 22:19:54.714265 [WARNING] fpm_request_check_timed_out(), line 158: child 22092, script '/home/htdocs/blog/index.php' (pool default) execution timed out (30.190051 sec), terminating
Jan 13 22:19:55.150269 [WARNING] fpm_request_check_timed_out(), line 158: child 22092, script '/home/htdocs/blog/index.php' (pool default) execution timed out (30.626056 sec), terminating
Jan 13 22:19:55.280294 [WARNING] fpm_request_check_timed_out(), line 158: child 22092, script '/home/htdocs/blog/index.php' (pool default) execution timed out (30.756072 sec), terminating
Jan 14 04:25:10.246332 [NOTICE] fpm_children_make(), line 352: child 19682 (pool default) started
Jan 14 04:26:46.671126 [WARNING] fpm_request_check_timed_out(), line 158: child 5197, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.014729 sec), terminating
Jan 14 04:26:46.673180 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 14 04:26:46.673227 [WARNING] fpm_children_bury(), line 215: child 5197 (pool default) exited on signal 15 SIGTERM after 11397.233579 seconds from start
Jan 14 04:26:46.674141 [NOTICE] fpm_children_make(), line 352: child 21862 (pool default) started
Jan 14 04:28:36.335704 [WARNING] fpm_request_check_timed_out(), line 158: child 22099, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.007718 sec), terminating
Jan 14 04:28:36.338527 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 14 04:28:36.338580 [WARNING] fpm_children_bury(), line 215: child 22099 (pool default) exited on signal 15 SIGTERM after 22318.115787 seconds from start
Jan 14 04:28:36.339512 [NOTICE] fpm_children_make(), line 352: child 24364 (pool default) started
Jan 14 04:28:36.597695 [WARNING] fpm_request_check_timed_out(), line 158: child 13424, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.047650 sec), terminating
Jan 14 04:28:36.601724 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 14 04:28:36.601783 [WARNING] fpm_children_bury(), line 215: child 13424 (pool default) exited on signal 15 SIGTERM after 10378.102868 seconds from start
Jan 14 04:28:36.602722 [NOTICE] fpm_children_make(), line 352: child 24366 (pool default) started
Jan 14 04:31:25.990795 [WARNING] fpm_request_check_timed_out(), line 158: child 22102, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.006149 sec), terminating
Jan 14 04:31:25.993590 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 14 04:31:25.993646 [WARNING] fpm_children_bury(), line 215: child 22102 (pool default) exited on signal 15 SIGTERM after 22487.768873 seconds from start
Jan 14 04:31:25.994576 [NOTICE] fpm_children_make(), line 352: child 1777 (pool default) started
Jan 14 04:31:46.625603 [WARNING] fpm_request_check_timed_out(), line 158: child 22103, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.074709 sec), terminating
Jan 14 04:31:46.628291 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD
Jan 14 04:31:46.628359 [WARNING] fpm_children_bury(), line 215: child 22103 (pool default) exited on signal 15 SIGTERM after 22508.402867 seconds from start
查过网上的资源,基本都是认为是php线程打开文件句柄受限导致的错误。具体的解决的办法如下:
1、提升服务器的文件句柄打开打开
/etc/security/limits.conf : (增加)
* soft nofile 51200
* hard nofile 51200
# vi /etc/security/limits.conf 加上
* soft nofile 51200
* hard nofile 51200
* 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
底部添加
fs.file-max=51200
完成以上修改,重启PHP,警告信息再也没了。
世界从此安宁,502 Bad Gateway 没有了。