温馨提示×

Debian下Nginx怎么启动

小樊
44
2026-07-21 20:36:37
栏目: 智能运维

在 Debian 系统下,启动 Nginx 通常使用 systemd 来管理服务。下面是常用操作:

1. 启动 Nginx

sudo systemctl start nginx

2. 设置开机自启

sudo systemctl enable nginx

3. 查看 Nginx 状态

sudo systemctl status nginx

4. 停止 Nginx

sudo systemctl stop nginx

5. 重启 Nginx

sudo systemctl restart nginx

6. 重新加载配置(不中断服务)

sudo systemctl reload nginx

7. 确认 Nginx 是否已安装

nginx -v

dpkg -l | grep nginx

如果没有安装,可以先安装:

sudo apt update
sudo apt install nginx

8. 常见问题排查

  • 端口被占用(如 80 端口):
    sudo ss -tlnp | grep 80
    
  • 配置文件错误
    sudo nginx -t
    

如果你是在 Docker / WSL / 非 systemd 环境(如某些容器),可以告诉我,我再给你对应的启动方式。

0