Nginx 遇到 502 Bad Gateway 自动重启脚本
放到crontab里一分钟执行一次。URL和CMD根据自己的改。
#!/usr/bin/php
<?
$url = 'http://www.diahosting.com';
$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搜索
页:
[1]