From c31d1cc450ced185afdfd0e6253213ce643a2947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Fri, 4 Sep 2026 09:55:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(nginx):=20/api=20=E5=8F=8D=E4=BB=A3?= =?UTF-8?q?=E6=8C=89=20TTL=20=E9=87=8D=E8=A7=A3=E6=9E=90=20backend=20DNS?= =?UTF-8?q?=E2=80=94=E2=80=94=E6=A0=B9=E6=B2=BB=20IP=20=E6=BC=82=E7=A7=BB?= =?UTF-8?q?=E5=90=8E=20502?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nginx 对 hostname 的 proxy_pass 只在启动时解析一次并永久缓存,backend 重建或网络栈劣化后持续 502(2026-09-03/04 两次实战,重启 frontend 才恢复)。 改用 docker 内嵌 DNS 127.0.0.11 + resolver valid=10s + variable proxy_pass(不带 URI,仍转发原始 /api/... 完整路径,行为不变)。 Co-Authored-By: Claude Code --- yunkes/nginx.conf | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/yunkes/nginx.conf b/yunkes/nginx.conf index a742879..85df655 100644 --- a/yunkes/nginx.conf +++ b/yunkes/nginx.conf @@ -24,8 +24,15 @@ server { # network; if the name changes, update here. Streaming endpoints # (/api/media/) work without buffering because we turn proxy_buffering # off — matches the dev-server behaviour (vite proxies /api/media first). + # + # DNS 加固(2026-09-04):nginx 默认启动时解析一次 hostname 并永久缓存, + # backend 重建/IP 漂移后 502(两天两次实战)。改用 docker 内嵌 DNS + # (127.0.0.11)按 TTL 重解析——variable proxy_pass 不带 URI,仍转发 + # 原始完整请求路径(/api/...),与原行为一致。 location /api/ { - proxy_pass http://backend:8000; + resolver 127.0.0.11 valid=10s ipv6=off; + set $yunke_backend http://backend:8000; + proxy_pass $yunke_backend; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;