Centos5、6的启动脚本存放在:/etc/init.d/目录下
Centos7 的启动脚本入存放在:/lib/systemd/system/ 目录下
创建 nginx脚本
vim /lib/systemd/system/nginx.service
脚本内容:
[Unit]
Description=nginx
After=network.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
启动 nginx 服务
systemctl start nginx
停止 nginx 服务
systemctl stop nginx
重启 nginx 服务
systemctl restart nginx
查看 nginx 服务状态
systemctl status nginx
设置/取消开机启动
systemctl enable nginx
systemctl disable nginx