Centos版本:7.4
image.png
nginx版本:1.15.5
image.png
系统操作用户:root
image.png
步骤:
1.新建nginx.service服务文件
vim /usr/lib/systemd/system/nginx.service
2.nginx.service文件的内容
[Unit]
Description=Nginx Server Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
3.这里有2个参数需要注意下
Ⅰ.PIDFile参数,对应nginx.conf文件pid的位置
image.png
Ⅱ.ExecStart参数,这里我的安装路径是"/usr/local/nginx/sbin",更改为各自的安装路径
4.刷新systemctl
systemctl daemon-reload
5.启动nginx
systemctl start nginx
5.设置nginx开机自启动
systemctl enable nginx
网友评论