From dbcddc87b4168ada80de5f63aae7f8ce67541966 Mon Sep 17 00:00:00 2001 From: saas-backend-agent Date: Thu, 3 Sep 2026 15:20:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(infra):=20web=20=E5=AE=B9=E5=99=A8=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=97=B6=E8=A6=86=E7=9B=96=20nginx=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E9=98=B2=E6=AD=A2=E7=8E=AF=E5=A2=83=E9=94=99?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:staging web 容器 nginx upstream 指向 xiaoxia-api-production, 原因是镜像被 skip 构建后 retag 了旧镜像(内含 production 默认配置)。 staging 容器在 xiaoxia-net-staging 网络无法解析 production 容器名, 导致 DNS 失败 → nginx 崩溃重启 → 502。 修复:compose.yml 为 web 服务添加 volume mount,运行时将正确环境的 nginx 配置文件挂载到 /etc/nginx/conf.d/default.conf,覆盖镜像内的默认配置。 - staging: ./nginx-staging.conf → xiaoxia-api-staging:8000 - production: ./nginx-production.conf → xiaoxia-api-production:8000 注意:只挂载 nginx 配置文件,不挂载 /usr/share/nginx/html(静态文件)。 --- infra/docker/compose.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/infra/docker/compose.yml b/infra/docker/compose.yml index 614789d6e..91297553b 100755 --- a/infra/docker/compose.yml +++ b/infra/docker/compose.yml @@ -175,9 +175,14 @@ services: - xiaoxia-net # ========================================= - # 重要: 生产环境不要添加任何 volume 挂载到 /usr/share/nginx/html - # 这会导致静态文件被覆盖,返回 403 错误 + # Nginx 配置运行时覆盖 + # 确保容器使用正确环境的 nginx 配置,即使镜像构建时使用了默认配置 + # 注意: 只覆盖 /etc/nginx/conf.d/default.conf,不挂载 /usr/share/nginx/html # ========================================= + environment: + - NGINX_ENV=${ENV:-staging} + volumes: + - ./nginx-${ENV:-staging}.conf:/etc/nginx/conf.d/default.conf:ro healthcheck: test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:80"] -- 2.54.0