centos6.x是通过在/etc/init.d下新增Nginx脚本,然后添加chkconfig完成
实际在centos7.x的使用中上面的方法会出现问题
解决方法:改用systemcel
源码编译安装好Nginx之后
#在系统服务目录里创建Nginx.service文件
vi /lib/systemd/system/Nginx.service
[Unit]
Description=Nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/Nginx/sbin/Nginx -c /usr/local/Nginx/conf/Nginx.conf
ExecReload=/usr/local/Nginx/sbin/Nginx -s reload
ExecStop=/usr/local/Nginx/sbin/Nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
使用方法
#开机自启动
systemctl enable Nginx.service
#停止开机自启动
systemctl disable Nginx.service
#查询当前状态
systemctl status Nginx.service
#启动服务
systemctl start Nginx.service
#重新启动服务
systemctl restart Nginx.service
#停止服务
systemctl stop Nginx.service
#重新加载配置
systemctl reload Nginx.service
#查看所有已启动的服务
systemctl list-units --type=service
原文链接:https://www.f2er.com/centos/374409.html