vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=Nginx
Documentation=https://nginx.org
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=forking
Group=root
User=root
ExecStart=/opt/nginx/1.26.0/sbin/nginx
Restart=always
PrivateTmp=true
[Install]
WantedBy=multi-user.target
其中
/opt/nginx/1.26.0
为 Nginx 的安装目录
systemctl daemon-reload
systemctl enable nginx.service
附:操作命令
systemctl status nginx.service
systemctl start nginx.service
systemctl stop nginx.service
systemctl reload nginx.service
systemctl enable nginx.service
systemctl disable nginx.service