소스 검색

fix: 前端 nginx占位符问题

wuwenyi 5 일 전
부모
커밋
bcfa4154cb
4개의 변경된 파일20개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 0
      .gitignore
  2. 5 1
      gateway/Dockerfile
  3. 11 0
      gateway/docker-entrypoint.sh
  4. 2 2
      gateway/nginx.conf.template

+ 2 - 0
.gitignore

@@ -30,3 +30,5 @@ coverage/
 # 类型声明缓存
 *.tsbuildinfo
 *.iml
+
+.claude

+ 5 - 1
gateway/Dockerfile

@@ -1,2 +1,6 @@
 FROM nginx:1.27-alpine
-COPY nginx.conf /etc/nginx/conf.d/default.conf
+COPY nginx.conf.template /etc/nginx/conf.d/default.conf.template
+COPY docker-entrypoint.sh /
+RUN chmod +x /docker-entrypoint.sh
+ENTRYPOINT ["/docker-entrypoint.sh"]
+CMD ["nginx", "-g", "daemon off;"]

+ 11 - 0
gateway/docker-entrypoint.sh

@@ -0,0 +1,11 @@
+#!/bin/sh
+set -e
+
+# 默认值:测试环境用 docker-compose 内的 service name
+BACKEND_HOST=${BACKEND_HOST:-backend}
+
+echo "[nginx] BACKEND_HOST=${BACKEND_HOST}"
+
+envsubst '${BACKEND_HOST}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf
+
+exec "$@"

+ 2 - 2
gateway/nginx.conf → gateway/nginx.conf.template

@@ -6,7 +6,7 @@ server {
 
     # 后端 API 代理
     location /api/ {
-        proxy_pass http://qqflow-backend-test:8080/;
+        proxy_pass http://${BACKEND_HOST}:8080/;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -15,7 +15,7 @@ server {
 
     # 文件上传/下载代理
     location /uploads/ {
-        proxy_pass http://qqflow-backend-test:8080/uploads/;
+        proxy_pass http://${BACKEND_HOST}:8080/uploads/;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;