WenRou's Blog

新浪微薄腾讯微薄

最新碎语:测试图片碎语哦

您的位置:WenRou's Blog >lnamp> 解决Nginx 502 bad gateway错误自动重启脚本

解决Nginx 502 bad gateway错误自动重启脚本

502 bad gateway 最最烦人了,总是时不时的出现,解决 502 bad gateway的最好最终极的方法就是重启php-fpm。

所以首先,咱们要做个重启php-fpm的脚本。
 

  1. cd /home
     
  2. vi restart-php-fpm.sh
复制代码


输入如下代码,这个代码就是重启php-fpm的脚本了,脚本中的http://www.puhost.com 记得改成自己的网站哦
 

#!/usr/bin/php
<?
$url = ‘http://www.puhost.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.
先设置restart-php-fpm.sh的权限为755
 

  1. chmod 755 /home/restart-php-fpm.sh


运行crontab -e
 

  1. crontab -e


设置restart-php-fpm.sh自动 执行
 

  1. * * * * * /home/restart-php-fpm.sh


查看设置成功还是失败
 

  1. crontab -l

---

转载请注明本文标题和链接:《解决Nginx 502 bad gateway错误自动重启脚本

分享到:

发表评论

57 + 4 =
路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交