您现在的位置是:首页 > 博客日记 > Liunx Liunx

检测nginx是否正常,异常自动重启

2022-03-07 21:51:46 【Liunx】 人已围观

Check_Nginx_Server

  1. #!/bin/bash
  2. NginxServer='api.majiameng.com'
  3. time1=$(date "+%Y-%m-%d %H:%M:%S")
  4. heck_Nginx_Server()
  5. http_status_code=$(curl -m 5 -s -i -w %{http_code} -o/home/index.html $NginxServer)
  6. if [ $http_status_code -eq 000 -o $http_status_code -ge 500 ];then
  7. echo -e $time1"check http server error ,code is" $http_status_code
  8. systemctl restart nscd
  9. nginx -t
  10. nginx -s reload
  11. echo -e "nginx reload success"
  12. else
  13. http_content=$(curl -s ${NginxServer})
  14. #echo "service status ok \n "$http_content
  15. #echo -e $time1"service status ok ,code:"$http_status_code
  16. fi
  17. }


关注TinyMeng博客,更多精彩分享,敬请期待!
 

很赞哦! ()