
1.设置开机启动
systemctl enable nginx
2.修改自动重启配置文件
systemctl edit nginx
添加以下内容并保存
[Service]
Restart=always
RestartSec=5s
3.重新加载配置
systemctl daemon-reload
4.重启nginx
systemctl restart nginx
5.关闭nginx并验证是否自动重启
nginx -s stop(使用systemctl stop nginx命令不会自动重启)
等待5s后运行systemctl status nginx查看是否自动重启成功
另一个方式是定时重启
crontab -e
添加一行
0 3 * * * /usr/sbin/nginx -s reload
验证:crontab -l