# nginx 容器 root 配置修复 (#957) ## 问题 2026-08-11 用户访问 ai.qihuyun.com 时浏览器显示 "Welcome to nginx!" 默认欢迎页。 ## 根因诊断 经过逐步排查: 1. **架构真相**: 平台有**两层 nginx** - **宿主宝塔 nginx** (`/www/server/nginx/sbin/nginx` v1.30.1) — 监听 80/443 - **容器内 nginx** (`qihu-aiflow` 主容器内 v1.26.3) — 监听 8080,通过 docker-proxy 暴露为 12888 - ai.qihuyun.com.conf 在宝塔层**已经正确配置** `location ^~ / { proxy_pass http://127.0.0.1:12888; }` 2. **真正的 bug** 在容器内 aiflow.conf: - `location /` SPA fallback 块缺少 `root` 指令 - `location ~* \\.(svg|...)$` 块**有** `root /app/frontend/dist;` - 但 `location /` 块没有 → nginx 用默认 `/usr/share/nginx/html` - `/usr/share/nginx/html/index.html` 是 nginx 包默认安装的 615 bytes "Welcome to nginx" 页(2025-02-05 创建) 3. **症状**: 访问 `/` → `try_files $uri $uri/ /index.html` → 回退到 `/index.html` → nginx 用默认 root 找到 nginx 默认 welcome.html (615 bytes),而非真实的 `/app/frontend/dist/index.html` (544 bytes 的 QihuAI 前端) ## 修复 在 server 块(server 级,所有 location 继承)添加 `root /app/frontend/dist;`: ```nginx server { listen 8080 default_server; server_name _; root /app/frontend/dist; # <-- 新增(server 级) # location 块继承 server 级 root: location / { try_files $uri $uri/ /index.html; } } ``` ## 验证 | 测试 | 修复前 | 修复后 | |------|--------|--------| | 容器内 `curl http://127.0.0.1:8080/` | 615 bytes "Welcome to nginx" | **544 bytes 七虎AI** ✅ | | 宿主 `curl http://127.0.0.1:12888/` | 615 bytes | **544 bytes** ✅ | | 外部 `curl https://ai.qihuyun.com/` | Welcome 页 | **544 bytes 七虎AI** ✅ | | `/app/api/chat/conversations` | 403 | **403 Not authenticated** ✅ (API 正常) | ## 额外坑:nginx 多 master 累积 排查过程中发现容器内有多个 nginx master/worker 进程同时运行: - PID 14, 10329, 10553, 10687, 11855, 15571 — 历史多次 reload 累积 - 部分已成为 zombie(`State: Z`) - `nginx -s reload` 信号只发送给一个 master,其它 master 继续服务 - **解决方案**: `nginx -s stop` (发送 TERM),kill -9 残留进程,清 `/var/run/nginx.pid`,然后 `nginx` 启动单一 master ## safe-align - 修改文件: `/etc/nginx/conf.d/aiflow.conf` (容器内) - host git: `/www/wwwroot/qihuaiflow/nginx/aiflow.conf` - commit: #957