1.编辑systemctl服务配置文件
vim /usr/lib/systemd/system/nginx.service
2.内容如下
# 注意更改nginx启动命令 nginx.conf nginx.pid的路径
[Unit]
Description=nginx web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx-1.14.2/logs/nginx.pid
ExecStartPre=/usr/local/nginx-1.14.2/sbin/nginx -t -c /usr/local/nginx-1.14.2/conf/nginx.conf
ExecStart=/usr/local/nginx-1.14.2/sbin/nginx -c /usr/local/nginx-1.14.2/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3.重载系统服务
systemctl daemon-reload
4.启动nginx (启动前,记得把之前的先关闭)
systemctl start nginx
systemctl status nginx
5.设置开机启动
systemctl enable nginx
systemctl is-enabled nginx