502 Bad Gateway自动重启脚本

502 Bad Gateway自动重启脚本

literature
2022-05-26 / 0 评论 / 325 阅读 / 正在检测是否收录...

一个简单的脚本,用来监控502的,如果遇到502,自动重启PHP进程。适用于LNMP环境。

新建php.sh文件,存放于/root或其它目录:

#!/bin/bash
MY_URL="http://www.moerats.com/"
RESULT=`curl -I $MY_URL|grep "HTTP/1.1 502"`
if [ -n "$RESULT" ]; then
        /etc/init.d/php-fpm restart
fi

给予可执行权限:

chmod +x /root/php.sh

通过 crontab 设置自动运行:

crontab -e
* * * * * /root/php.sh

0

评论 (0)

取消