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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。