切换到/lib/systemd/system/目录,创建nginx.service文件
vim nginx.service
[unit]
description=nginx
after=network.target
[service]
type=forking
execstart=/usr/local/nginx/sbin/nginx
execreload=/usr/local/nginx/sbin/nginx reload
execstop=/usr/local/nginx/sbin/nginx quit
privatetmp=true
[install]
wantedby=multi-user.target
退出并保存文件,执行systemctl enable nginx.service使nginx开机启动
systemctl start nginx.service 启动nginx
systemctl stop nginx.service 结束nginx
systemctl restart nginx.service 重启nginx