#!/bin/bash url="https://www.cnblogs.com/shenjingwa/" status_code=$(curl -o /dev/null -s -w %{http_code} $url) if [ $status_code -eq 500 ]; then /etc/init.d/nginx restart fi
并在宝塔面板中设置计划任务,选择Shell脚本,执行时间为检测时间,我这里设置的是1分钟检测一次

按照以上设置即可
第二种方法,使用方法同上,当遇到Nginx停止时会自动重启
pgrep -x nginx &> /dev/null if [ $? -ne 0 ];then /etc/init.d/nginx restart fi
以上两种方法中的restart可更改为start
restart为重启命令
start为启动命令