操作需要root权限
1.创建文件
vim /etc/systemd/system/nginx.service
文件内容如下
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
2.重新加载 systemd
systemctl daemon-reload
3.在系统启动时启动服务
systemctl enable nginx
4.启动服务
systemctl start nginx