新建vi /lib/systemd/system/nginx.service在nginx.service文件
[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服务
systemctl start nginx.service
设置开机自启动nginx服务
systemctl enable nginx.service
停止开机自启动nginx服务
systemctl disable nginx.service
查看当前服务状态
systemctl status nginx.service
重新启动服务
systemctl restart nginx.service
查看所有已启动的服务
systemctl list-units --type=service