创建nginx.service文件
vim /lib/systemd/system/nginx.service
nginx.service的具体内容如下:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
nginx的启动路径,/usr/local/nginx/sbin/,根据实际情况填写
设置开机启动
systemctl enable nginx.service
启动nginx
systemctl start nginx.service
查看nginx状态
systemctl start nginx.service
重启nginx
systemctl restart nginx.service