Solution to php-fpm frequent 502
For more, please support: www.Bkjia.com
Recently, nginx often gets 502. The best way to solve 502 is to restart php-fpm.
It is still troublesome to restart manually. The best thing is to throw it into the shell.
vim restart-php-fpm.sh
#!/bin/sh
SERVICE='php-fpm'
#if ps ax | grep -v grep | grep $SERVICE > /dev/null
if netstat -anp | grep 9000 > /dev/null
then
echo $SERVICE service running, everything is fine
else
echo $SERVICE is not running
service php-fpm start
fi
Copy after login
I tested it on the local virtual machine and it worked. I threw it on the server. It turned out that when I got 502, it was not that php-fpm had no process, but that php-fpm was dead.
So I took another option:
vim restart-php-fpm.sh
#!/bin/bash
MY_URL=http://www.webyang.net
RESULT='curl -I $MY_URL | grep HTTP/1.1 502\'
if [ -n $RESULT ]; then
#如果502则会执行这里的内容,随便加或改
killall -9 php-cgi
service php-fpm restart
fi
Copy after login
In this case, it is still manual. If you need it automatically, add it to the crontab yourself.
chmod 755 restart-php-fpm.sh
Run crontab -e
Set restart-php-fpm.sh to execute automatically every minute (the time can be adjusted according to your own requirements)
*/1 * * * * /home/restart-php-fpm.sh
Check whether the setting is successful or failed
crontab -l
Or write a shell infinite loop and execute it after a period of time.
http://www.bkjia.com/PHPjc/953324.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/953324.htmlTechArticlephp-fpm often appears 502 solution. For more solutions, please support: www.Bkjia.com nginx often 502 recently, solve it 502 The best way is to restart php-fpm. Manually restarting is still troublesome...