1、在系统服务目录里创建nginx.service文件
vi /usr/lib/systemd/system/nginx.service
2、写入内容如下:
[Unit]
Description=nginx
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
3、设置开机自启动
systemctl enable nginx.service
4、查看nginx状态
systemctl status nginx.service
5、显示Active: inactive (dead),杀死nginx重启nginx
pkill -9 nginx
ps aux | grep nginx
systemctl start nginx
systemctl status nginx.service
6、查看状态,变成了active,已经设置好开机启动。重启服务器
reboot
7、再次连接后,查看服务状态
systemctl status nginx.service
© 版权声明
THE END
暂无评论内容