centos 7 下设置nginx项目开机自启动
1.1在/etc/systemd/system 下创建xxx.service文件;如:nginx.service
1.1.nginx.service文件添加:
[Unit]
Description=nginx service
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbing/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2.使自启动生效
systemctl enable nginx.service
3.立即启动项目服务
systemctl start nginx.service
systemctl stop nginx.service
systemctl restart nginx.service
systemctl list-units --type=service
ps -ef | grep nginx
4.查看服务状态:
systemctl status nginx.service
5.重启服务:
shutdown -r now
6.重启后访问:http://ip:port/