Using LNmp for a while, but when traffic is heavy, sometimes Nginx 502 Bad Gateway will appear inexplicably, not php-fpm is dead, or nginx is dead. When there are many websites, there is no time to check them one by one every day. It is often found that the website dwon is discovered after 1 or 2 days, and the traffic is lost a lot. Easy to give a way to solve such errors, automatically detect whether the computer configuration website is normal, if not normal, then automatically restart LNmp. First, create a php file test200.php in the root directory of the website, and write a few words at random, such as:
<?php echo "200_OK"; ?>
Then create a script vi test200_monitor. The contents of the sh script are as follows:
wget http://www.piaoyi.org/test200.php --spider c_monitor=$? if [ $c_monitor = "1" ]; then echo "# Error no 200 Status, time: " $(date +"%y-%m-%d %H:%M:%S") "restart lnmp.. " |
Mail -s "Critical Info: Website is offline." [email protected] /usr/local/php/sbin/php-fpm restart echo "restart lnmp: php-fpm" fi
Just monitor the http://www.piaoyi.org/test200.php page and restart PHP if it is not a 200 status code. The command line /usr/local/php/sbin/php-fpm restart can be replaced with other commands, such as /root/lnmp restart. Change your mailbox to your own and send you an email each time an error occurs. [Supplement vi vim usage]: i enter edit state; :wq save exit; :q! Exit without saving. Then set the permissions:
chmod 777 /root/test200_monitor.sh
Run the timer:
crontab -e
Enter the following to check every 5 minutes
*/5 * * * * /root/test200_monitor.sh
Ok, you're done. You can work with confidence, lnmp will no longer appear 502 Bad Gateway error. If you want to run the command line directly in the php script, you can create a php file monitor.php in the root directory of the website. The contents are as follows:
<? $url = 'http://www.piaoyi.org' $cmd = '/usr/local/php/sbin/php-fpm restart'; $exec = "curl --connect-timeout 5 -I $url 2>/dev/null"; $res = shell_exec($ Exec); if(stripos($res,'502 Bad Gateway') !== false){ shell_exec($cmd); exit(); } ?>
Then, as above, add a row to run with crontab Command, online monitoring can be.
Problem Description: After posting the website/WCF to IIS, it was reported to be wrong. Reason: A
Recently, some netizens reported that when Windows XP comes with the “Remote Desk
The Web server is built on the line, and it can carry large amount of traffic, res
cited: In the eyes of many network administrators, managing the server may be a relatively simple th
What should be paid attention to in the management of enterprise leased servers?
Server Purchasing Cheats: Choose what you want to know
How to enhance asp.net 1.1 /2.0 security - anti-cross-site attack
How to remotely restart NT server with port 139
Eight energy-saving methods in the data center Green and more economical
Enable Gzip compression (HTTP compression) on IIS
How to unlock the automatic lock of Win2003?
The default share helps you manage the FTP server
Blank password causes remote connection Server2008 failure
What should I do if the Win7 network and sharing center are open?
Back up system information Some points you need to know
Introduction and application of CAD common button functions
How to play a big role in idle small U disk
Escort protection Thunder download security four strokes
To create "copper wall iron wall" for win2003, set system firewall
Share the best way to restrict access to your computer's disk using Windows XP Group Policy
Modify the domain name resolution file hosts file