1.先创建开机自启脚本
cd /etc/systemd/system
vi nginx.service
内容:
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2.设置开机自启动
systemctl enable nginx
3.启动nginx服务
systemctl start nginx.service
重新启动服务
systemctl restart nginx.service
查看服务当前状态
systemctl status nginx.service
停止开机自启动
systemctl disable nginx.service