From fdbf8839c5abd7257584b23c9d501116aac3ce16 Mon Sep 17 00:00:00 2001 From: chengkai3 Date: Sat, 27 Jun 2026 18:17:00 +0800 Subject: [PATCH] =?UTF-8?q?[fix]:[FL-196][nginx=20=E5=8A=A8=E6=80=81=20DNS?= =?UTF-8?q?=20=E8=A7=A3=E6=9E=90=20+=20=E9=83=A8=E7=BD=B2=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E4=B8=AD=E9=87=8D=E5=90=AF=20nginx=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=AE=B9=E5=99=A8=E9=87=8D=E5=90=AF=E5=90=8E=20502]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 18 ++++++++++++++++++ deploy/pro-deploy/nginx.conf | 13 ++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9a336b9..229cea2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -230,3 +230,21 @@ jobs: exit 1 fi compose_run ps + + - name: 重启 nginx 清 DNS 缓存 + uses: appleboy/ssh-action@v1.2.0 + env: + DEPLOY_PATH: ${{ secrets.DEPLOY_PATH || vars.DEPLOY_PATH }} + with: + host: ${{ secrets.SERVER_HOST || vars.SERVER_HOST }} + username: ${{ secrets.SERVER_USER || vars.SERVER_USER }} + port: ${{ secrets.SERVER_PORT || vars.SERVER_PORT || 22 }} + timeout: 60s + command_timeout: 30s + key: ${{ secrets.SERVER_SSH_KEY }} + password: ${{ secrets.SERVER_PASSWORD }} + envs: DEPLOY_PATH + script: | + DEPLOY_DIR="${DEPLOY_PATH:-/opt/fquiz}" + cd "${DEPLOY_DIR}" + docker compose -p "$(awk -F= '/^COMPOSE_PROJECT_NAME=/{print $2; exit}' deploy/pro-deploy/.env | tr -d '[:space:]')" -f deploy/pro-deploy/compose.yml restart proxy diff --git a/deploy/pro-deploy/nginx.conf b/deploy/pro-deploy/nginx.conf index c64c545..aa6252b 100644 --- a/deploy/pro-deploy/nginx.conf +++ b/deploy/pro-deploy/nginx.conf @@ -4,8 +4,13 @@ server { client_max_body_size 200m; + # Docker internal DNS resolver — forces nginx to re-resolve service names + # at runtime instead of caching IPs at startup (fixes 502 after container restart) + resolver 127.0.0.11 valid=10s; + location /api/v1/ws { - proxy_pass http://api:8000; + set $backend_api "http://api:8000"; + proxy_pass $backend_api; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -18,7 +23,8 @@ server { } location /api/ { - proxy_pass http://api:8000; + set $backend_api "http://api:8000"; + proxy_pass $backend_api; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -29,7 +35,8 @@ server { } location / { - proxy_pass http://web:3000; + set $backend_web "http://web:3000"; + proxy_pass $backend_web; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;