nano /etc/systemd/system/nginx.service
[Unit]
Description=Nginx Web Server
After=network.target
[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStart=/usr/local/bin/nginx -c /opt/nginx/conf/nginx.conf -p /opt/nginx
ExecReload=/usr/local/bin/nginx -s reload
ExecStop=/usr/local/bin/nginx -s quit
Restart=always
[Install]
WantedBy=multi-user.target
sudo pkill -9 nginx
sudo systemctl daemon-reexec
sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl status nginx
● nginx.service - Nginx Web Server
Loaded: loaded (/etc/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2026-07-01 06:12:22 UTC
Main PID: 1937738 (nginx)
Tasks: 3
Memory: 10.2M
CPU: 25ms
✅ Nginx 已成功启动并运行!