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

Nginx 遇到502 Bad Gateway 自动重启的脚本代码,第1张

Nginx 遇到502 Bad Gateway 自动重启的脚本代码 原理就是用curl获取HTTP头,发现502状态码就执行重启php-fpm的命令。
复制代码 代码如下:
#!/usr/bin/php
<!--$url = 'https://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搜索或参考下面的文章
https://www.jb51.net/LINUXjishu/19905.html
https://www.jb51.net/LINUXjishu/17374.html

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/895992.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-14
下一篇 2022-05-14

发表评论

登录后才能评论

评论列表(0条)

保存