谷歌给你找了一个,善用搜索。 #!/bin/bash # author: 龙笑天 # website: https://www.ilxtx.com/linux-shell-auto-restart-nginx.html # 检查 nginx 的状态 curl -s nginx_status > /dev/null 2>&1 # 如果 nginx 没有运行 if [ $? -ne 0 ] then echo "Nginx is not running. Restarting Nginx." /etc/init.d/nginx restart else echo "Nginx is running." fi