Http://yangjunwei.com/a/723.html
Analysis of LNMP frequent 502 bad gateway issues in the CentOS system 2012-01-28 Yang JunweiPost a comment(1)
Recently the VPS always appear Nginx 502 bad Gateway error, cause the webpage cannot access normally, but FTP and SSH connect normally, it is nerve-racking! This time, good treatment!
According to the problem, it should be php-fpm problem, first check the log file/usr/local/php/logs/php-fpm.log
The log content is roughly the following (borrowed 28, 292 days of Records):
Jan 22:50:00.309235 [NOTICE] Fpm_unix_init_main (), line 284:getrlimit (nofile): max:1024, Cur:1024jan 28 22:50:00.3095 [NOTICE] Fpm_event_init_main (), line 88:libevent:using Epolljan-22:50:00.309617 [NOTICE] Fpm_init (), line 52:fpm is running, PID 7967Jan 22:50:00.310444 [NOTICE] Fpm_children_make (), line 352:child 7968 (pool default) Startedjan 28 22:50:00.311328 [NOTICE] Fpm_children_make (), line 352:child 7969 (pool default) Startedjan 22:50:00.312208 [NOTICE] Fpm_children_make (), line 352:child 7970 (pool default) Startedjan-22:50:00.313161 [NOTICE] Fpm_children_make (), line 352:child 7971 (pool default) Startedjan 22:50:00.314210 [NOTICE] Fpm_children_make (), line 352:child 7972 (pool DEFA ult) Startedjan 22:50:00.314242 [NOTICE] Fpm_event_loop (), line 107:libevent:entering main Loopjan 29 16:58:30.845059 [NOTICE] fpm_got_signal (), line 70:received Sigusr2jan 16:58:30.856418 [NOTICE] Fpm_pctl (), line 256:switching to ' r Eloading ' Statejan 29 16:58:30.856449 [NOTICE] Fpm_pctl_kill_all (), line 172:sending signal 3 sigquit to child 7972 (pool default) Jan 29 16:58:30. 856463 [NOTICE] Fpm_pctl_kill_all (), line 172:sending signal 3 sigquit to child 7971 (pool default) Jan 29 16:58:30.856475 [NOTICE] Fpm_pctl_kill_all (), line 172:sending signal 3 sigquit to child 7970 (pool default) Jan 16:58:30.856487 [Noti CE] Fpm_pctl_kill_all (), line 172:sending signal 3 sigquit to child 7969 (pool default) Jan 16:58:30.856537 [NOTICE] FP M_pctl_kill_all (), line 172:sending signal 3 sigquit to child 7968 (pool default) Jan 16:58:30.856546 [NOTICE] Fpm_pctl _kill_all (), line 181:5 children is still Alivejan [16:58:35.845629] NOTICE (), line Fpm_pctl_kill_all si Gnal SIGTERM to Child 7972 (pool default) Jan 16:58:35.845662 [NOTICE] Fpm_pctl_kill_all (), line 172:sending signal SIGTERM to Child 7971 (pool default) Jan 16:58:35.845671 [NOTICE] Fpm_pctl_kill_all (), line 172:sending signal SI Gterm to Child 7970 (pooL default) Jan 16:58:35.845678 [NOTICE] Fpm_pctl_kill_all (), line 172:sending signal-SIGTERM to Child 7969 (pool def Ault) Jan 16:58:35.845686 [NOTICE] Fpm_pctl_kill_all (), line 172:sending signal-SIGTERM to child 7968 (pool default) Jan 16:58:35.845691 [NOTICE] Fpm_pctl_kill_all (), line 181:5 children is still Alivejan 16:58:36.450929 [NOTICE] F Pm_got_signal (), line 48:received Sigchldjan 16:58:36.451016 [WARNING] Fpm_children_bury (), line 215:child 7968 (pool Default) exited on signal SIGTERM after 65319.297391 seconds from Startjan 16:58:36.451062 [WARNING] Fpm_children_b Ury (), line 215:child 7971 (pool default) exited on signal SIGTERM after 65319.294705 seconds from Startjan 29 16:58:3 6.451088 [WARNING] Fpm_children_bury (), line 215:child 7972 (pool default) exited on signal SIGTERM after 65319.293684 Seconds from Startjan 16:58:36.451103 [NOTICE] fpm_got_signal (), line 48:received Sigchldjan 16:58:36.451834 [Noti CE] Fpm_got_signal (), LiNE 48:received Sigchldjan 16:58:36.451868 [WARNING] Fpm_children_bury (), line 215:child 7969 (pool default) exited on Signal SIGTERM after 65319.297343 seconds from Startjan 16:58:36.451891 [WARNING] Fpm_children_bury (), line 215:ch ILD 7970 (pool default) exited on signal SIGTERM after 65319.296487 seconds from Startjan 16:58:36.451903 [NOTICE] F Pm_pctl_exec (), Line 95:RELOADING:EXECVP ("/usr/local/php/bin/php-cgi", {"/usr/local/php/bin/php-cgi", "--fpm", "-- Fpm-config ","/usr/local/php/etc/php-fpm.conf "})
Eyeful of the notice error, it is observed that the next few days, the error log is so! According to network data analysis, this kind of error is mostly due to the PHP thread open file handle is limited caused by the error, here comprehensive children's shoes analysis, collation record as follows, hope to solve such 502 problems!
First check the value of the ulimit-n, SSH input command:
# Ulimit-n back: 65535
1. Raise the file handle of the server to open
SSH command: # vi/etc/security/limits.conf, add the following at the end:
* Soft Nofile 65535* hard nofile 65535
2, increase the number of open Nginx process file
# vi/usr/local/nginx/conf/nginx.conf View Worker_rlimit_nofile 51200;
3. Modify the php-fpm.conf configuration file
The option in Ulimit-n value of 65535,/usr/local/php/etc/php-fpm.conf is confirmed earlier rlimit_files ensure that this value is consistent.
<value name= "Rlimit_files" >65535</value><value name= "max_requests" >10240</value>
4, modify the sysctl.conf
# vi/etc/sysctl.conf
Bottom add
fs.file-max=65535
At this point, restart/root/lnmp Restart effective, to see if there is any similar error messages appear!
PS. To reduce the Php-fpm.log file size, you can change the log level in the/usr/local/php/etc/php-fpm.conf from notice to ERROR, which slows down the generation of logs!
Log level <value name= "Log_level" >Error</value>
2012.02.20 update: Seemingly 502 bad Gateway has disappeared!!
PHP-FPM always warning process exit issues