fix(nginx): /api 反代按 TTL 重解析 backend DNS——根治 IP 漂移后 502
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 <noreply@anthropic.com>
This commit is contained in:
+8
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user