温馨提示×

nginx在debian上如何启动

小樊
65
2026-10-09 11:17:16
栏目: 智能运维

在 Debian 上启动 nginx 通常有以下几种方式,取决于你是通过 apt 安装还是源码编译安装。


一、通过 apt 安装的 nginx(最常见)

1. 启动 nginx

sudo systemctl start nginx

2. 设置开机自启

sudo systemctl enable nginx

3. 查看运行状态

sudo systemctl status nginx

4. 停止 / 重启

sudo systemctl stop nginx
sudo systemctl restart nginx

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

sudo systemctl reload nginx

二、源码编译安装的 nginx(无 systemd 服务)

如果你是手动 make && make install 安装的:

1. 直接运行

sudo /usr/local/nginx/sbin/nginx

2. 停止

sudo /usr/local/nginx/sbin/nginx -s stop

3. 重新加载配置

sudo /usr/local/nginx/sbin/nginx -s reload

三、验证 nginx 是否启动成功

curl http://localhost

或浏览器访问:

http://服务器IP

看到 Welcome to nginx! 即成功。


四、常见问题

1. 端口被占用(如 80 被 apache 占用)

sudo lsof -i:80

2. 配置文件测试

sudo nginx -t

如果你是 Docker / Debian 最小化系统 / 特定版本,可以告诉我,我可以给你更精确的命令。

0 踩