Centos5、6的启动脚本存放在:/etc/init.d/目录下
Centos7 的启动脚本入存放在:/lib/systemd/system/ 目录下

创建 nginx脚本

  1. vim /lib/systemd/system/nginx.service

脚本内容:

  1. [Unit]
  2. Description=nginx
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  7. ExecReload=/usr/local/nginx/sbin/nginx -s reload
  8. ExecStop=/usr/local/nginx/sbin/nginx -s stop
  9. PrivateTmp=true
  10. [Install]
  11. WantedBy=multi-user.target

启动 nginx 服务

  1. systemctl start nginx

image.png

停止 nginx 服务

  1. systemctl stop nginx

image.png

重启 nginx 服务

  1. systemctl restart nginx

image.png

查看 nginx 服务状态

  1. systemctl status nginx

image.png

设置/取消开机启动

  1. systemctl enable nginx
  2. systemctl disable nginx

image.png