Received an alert email today prompting the website 502 Bad Gateway,
You cannot open the Web site URL after entering it:
Log on to the server to see Nginx process OK:
To view the FASTCGI process has stopped running:
Problems found after the search is what the cause of the problem, the first fastcgi process started after the site can access the reasons for fine.
View PHP log tail–n 1000/usr/local/php/logs/php-fpm.log
"Linux commune http://www.linuxidc.com"
Find the alarm point in the log information, where the highlight is the problem, the system maximum number of files is 1024, and the current number of open files is 1024, view php-fpm.conf:
<value name= "Rlimit_files" >65535</value>
So is the system file opening number becomes the bottleneck, causes the PHP open file number to reach the system default maximum value and stops the process.
Then increase the number of system files.
#ulimit –HSN 65535
#echo ' ULIMIT–HSN 65535 ' >>/etc/profile
#echo ' ULIMIT–HSN 65535 ' >>/etc/rc.local
# vim/etc/security/limits.conf
* Soft Nofile 65535
* Hard Nofile 65535
For servers that can reboot the system, it is best to reboot so that the changed parameters take effect globally.
A script that monitors PHP and is able to restart automatically:
#cat/usr/local/bin/fastcgi_monitor.sh
#!/bin/sh
#xxx监控
#!/bin/bash
State= ' Curl--head http://www.linuxidc.net | awk ' Nr==1 ' | awk ' {print $} '
If ["$STATE"-eq "502"]; Then
/etc/init.d/fastcgi restart
echo "FastCGI restarted" | Mutt-s "x.x.x.x website server fastcgi restarted" [email protected]
elif ["$STATE"-ne "502"] && ["$STATE"-ne "200"]; Then
/etc/init.d/nginx restart
/etc/init.d/fastcgi restart
echo "fastcgi and Nginx restarted" | Mutt-s "x.x.x.x website server fastcgi and Nginx restarted" [email protected]
Fi
*/10 * * * * sh/usr/local/bin/fastcgi_monitor.sh >/tmp/fastcgi_monitor.log 2>&1 &