From 4389ec1944cb4e7560281cda4d922a1f6f64e073 Mon Sep 17 00:00:00 2001 From: xianshi3 Date: Mon, 17 Aug 2026 05:05:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(nginx):=20=E7=BD=91=E5=85=B3=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=E9=87=8D=E5=90=AF=E5=90=8E=E5=89=8D=E7=AB=AF=20502=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nginx 启动时将 mes-gateway 域名解析结果缓存为固定 IP, 网关容器重建(IP 变化)后前端持续 502, 需重启前端才恢复。 改用 Docker 内嵌 DNS(127.0.0.11, valid=30s)动态解析。 --- mes-frontend/nginx.conf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mes-frontend/nginx.conf b/mes-frontend/nginx.conf index faff98c..3610c30 100644 --- a/mes-frontend/nginx.conf +++ b/mes-frontend/nginx.conf @@ -42,8 +42,12 @@ server { } # Proxy API to backend (Spring Cloud Gateway) + # 用 Docker 内嵌 DNS (127.0.0.11) 动态解析:网关容器重启换 IP 后 + # nginx 不会继续往旧 IP 转发(否则会一直 502 直到前端重启) location /api/ { - proxy_pass http://mes-gateway:9090/api/; + resolver 127.0.0.11 valid=30s ipv6=off; + set $gateway_upstream http://mes-gateway:9090; + proxy_pass $gateway_upstream; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;