CentOS7 Nginx 服务化、开机自启动

Scroll Down

直接上命令:

vi /usr/lib/systemd/system/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

相关操作命令:

systemctl daemon-reload
systemctl enable nginx.service
systemctl start nginx.service