首页 > 网站 > 建站经验 > 正文

Nginx 遇到502 Bad Gateway 自动重启的脚本代码

2019-11-02 16:15:39
字体:
来源:转载
供稿:网友
原理就是用curl获取HTTP头,发现502状态码就执行重启php-fpm的命令。

复制代码 代码如下:

#!/usr/bin/php

<!--$url = 'http://www.jb51.net';

$cmd = '/usr/local/php/sbin/php-fpm restart';

for($i = 0; $i < 5; $i ++){ $exec = "curl connect-timeout 3 -I $url 2>/dev/null";

$res = shell_exec($exec);

if(stripos($res, '502 Bad Gateway') !== false){

shell_exec($cmd);

exit();

}

}

-->

至于crontab,请自行Google搜索或参考下面的文章

http://www.jb51.net/LINUXjishu/19905.html

http://www.jb51.net/LINUXjishu/17374.html
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表