美文网首页
Nginx 502 Bad Gateway 自动重启脚本

Nginx 502 Bad Gateway 自动重启脚本

作者: dongshixiao | 来源:发表于2018-05-10 14:02 被阅读0次

    需要确保系统已安装curl,centos可以执行:yum install curl,debian/ubuntu可以执行:apt-get install curl

    1.写一个简单的502.php页面,可以通过域名或者ip访问,比如baidu.com/502.php。

    2.创建shell脚本

    #!/bin/bash
    # author: season
    # website: http://xxxx/502.php
    
    CheckURL="http://xxxx/502.php"
    
    STATUS_CODE=`curl -o /dev/null -m 10 --connect-timeout 10 -s -w %{http_code} $CheckURL`
    #echo "$CheckURL Status Code:\t$STATUS_CODE"
    if [ "$STATUS_CODE" = "502" ]; then
            #重启操作 根据自己需求
            #/etc/init.d/php-fpm restart
        lnmp httpd restart
        
        now_time='['$(date +"%Y-%m-%d %H:%M:%S")']'
        echo ${now_time} >>  /root/502.log.txt
    
    fi
    

    增加可执行
    chmod +x /root/502.sh
    3.测试是否可以正常执行
    4.添加到计划任务,一分钟执行一次即可。
    计划任务教程:https://www.vpser.net/manage/crontab.html

    原理就是用curl获取HTTP头,发现502状态码就执行重启php-fpm的命令。

    相关文章

      网友评论

          本文标题:Nginx 502 Bad Gateway 自动重启脚本

          本文链接:https://www.haomeiwen.com/subject/kjvzrftx.html