feat(deploy): 添加环境配置模板 + 修复 compose 路径 bug #1628
Reference in New Issue
Block a user
Delete Branch "feat/config-templates-phase2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
变更内容
新增文件
deploy/configs/.env.staging — Staging 环境配置模板
${PLACEHOLDER}占位符标记PUBLIC_API_BASE_URL=https://staging-api.xiaoxiajianji.comGENERATED_FILES_HOST_DIR=/var/lib/xiaoxia-saas-staging/generateddeploy/configs/.env.production — Production 环境配置模板
PUBLIC_API_BASE_URL=https://api.xiaoxiajianji.comGENERATED_FILES_HOST_DIR=/var/lib/xiaoxia-saas-production/generateddeploy/configs/nginx-staging.conf — Staging Nginx 配置
xiaoxia-api-staging:8000deploy/configs/nginx-production.conf — Production Nginx 配置
xiaoxia-api-production:8000修复
GENERATED_FILES_HOST_DIR从:-默认值改为:?强制要求device: ${GENERATED_FILES_HOST_DIR:-/var/lib/xiaoxia-saas-staging/generated}(Production 缺省值时静默指向 staging)device: ${GENERATED_FILES_HOST_DIR:?GENERATED_FILES_HOST_DIR must be set in .env}(未设置则 docker compose 报错)其他
.gitignore:为deploy/configs/下的模板文件添加例外规则【阻塞级判定】
📊 审查概览
🔴 阻塞级问题(必须修复)
nginx-production.conf中proxy_pass指向的后端服务端口为8000,而在.env.production中定义的API_PORT为8001。这会导致 Nginx 无法正确连接到后端 API 容器,造成生产环境 502 Bad Gateway 错误。nginx-production.conf中的端口修改为8001,或者将.env.production中的端口修改为8000,确保两者一致。💡 改进建议(不阻塞合并)
[deploy/configs/nginx-production.conf:17-22] 缺少 index.html 的缓存控制头
location /中并未设置Cache-Control: no-cache等响应头(对比nginx-staging.conf中有显式配置)。这可能导致浏览器或 CDN 缓存了旧的 HTML 文件,导致新版本发布后用户访问到旧版本页面(白屏或报错)。建议参考 Staging 配置,增加location = /index.html块并设置禁用缓存的头。[.gitignore:27-28] 敏感文件提交风险
.gitignore中使用了!deploy/configs/.env.staging和!deploy/configs/.env.production强制提交规则。虽然当前提交的文件内容均为占位符(如${DATABASE_URL}),但此规则允许未来包含真实密钥的文件被提交。建议配合 Git Hook(如 pre-commit)或 Secret Scanner 工具,防止误将真实密钥写入这两个文件并提交到仓库。✅ 良好实践
infra/docker/compose.yml中使用了${GENERATED_FILES_HOST_DIR:?...}语法,强制要求环境变量必须设置,避免了因变量缺失导致的默认路径挂载错误,增强了生产环境的安全性。🤖 由 AI 代码审查机器人自动生成 | 2026-09-02 07:30:40 | 模型:
🚀 预览环境已部署
🗑️ 预览环境已清理
PR #1628 已关闭或合并,对应的预览环境已被清理。