centos7 systemctl启动方式添加nginx.service服务
进入到 /usr/lib/systemd/system 目录下,编辑文件 nginx.service 1.cd /usr/lib/systemd/system/ 2.vi nginx.service 3. [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/run/nginx.pid ExecStartPre=/usr/bin/rm -f /run/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID KillMode=process KillSignal=SIGQUIT TimeoutStopSec=5 PrivateTmp=true [Install] WantedBy=multi-user.target 4.保存退出 #保存,重新加载 systemd 5.systemctl daemon-reload #设置nginx服务开机自启动 6.systemctl enable nginx.service #nginx服务常用操作 #启动nginx服务 systemctl start nginx.service #停止nginx服务 systemctl stop nginx.service #重启nginx服务 systemctl restart nginx.service #重新读取nginx配置(这个最常用, 不用停止nginx服务就能使修改的配置生效) systemctl reload nginx.service
参考地址:https://blog.csdn.net/wz947324/article/details/82149709