nginx php-fpm 502,nginx+php-fpm出现502错误的终极解决方案 | linux运维小站–linux系统架构_服务器运维_Linux运维工程师工作手札...

nginx+php-fpm出现502错误的终极解决方案

利用Nignx+php-fpm架构服务器的linux运维工程师们肯定都碰到过502 Bad Gateway错误的情况,出现502 Bad Gateway错误是由于php-fpm进程挂掉了,当然,当出现502 Bad Gateway错误的同时,我们也不得不说下504 timeout错误了。504错误是因为Php-fpm进程全部被占用,没有php进程来处理更多的访问引起的。这边有一个当网站出现502 Bad Gateway错误时自动去杀掉然后重启php-fpm的脚本。

#!/bin/sh

#502重启php

if [ -e /var/lock/subsys/502 ]

then

killall -9 curl 2>/dev/null

killall -9 php-fpm 2>/dev/null

/usr/local/webserver/php/sbin/php-fpm >/dev/null

echo "[ `date +'%h%d %T'` ] PHP-FPM died with no response, all processes restarted">>/data/logs/php.log

else

touch /var/lock/subsys/502

if [ `curl --connect-timeout 5 -I http://www.arezone.cn/ 2>/dev/null | grep '502 Bad Gateway' -c` != '0' ]

then

killall -9 php-fpm 2>/dev/null

/usr/local/webserver/php/sbin/php-fpm >/dev/null

echo "[ `date +'%h%d %T'` ] PHP-FPM died with 502 bad gateway, all processes restarted">>/data/logs/php.log

fi

rm -f /var/lock/subsys/502

fi

当出现502或者没有回应时写入日志文件

[ Mar24 09:14:01 ] PHP-FPM died with no response, all processes restarted

[ Mar26 08:39:01 ] PHP-FPM died with no response, all processes restarted

[ Mar26 08:41:00 ] PHP-FPM died with 502 bad gateway, all processes restarted

[ Mar26 08:44:01 ] PHP-FPM died with no response, all processes restarted

[ Mar26 09:37:02 ] PHP-FPM died with 502 bad gateway, all processes restarted

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值