From 2aef82d7ca6fad1791e3b24ffc211686a774fc05 Mon Sep 17 00:00:00 2001 From: yidl Date: Sun, 29 Jun 2025 00:29:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx.conf.gateway | 49 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/nginx.conf.gateway b/nginx.conf.gateway index ff2c118..f2afd33 100644 --- a/nginx.conf.gateway +++ b/nginx.conf.gateway @@ -94,15 +94,48 @@ http { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 关键 4: 重写后端返回的 Location 头(解决重定向端口丢失) - proxy_redirect https://sys_api/ http://$host:$server_port/auth/; - proxy_redirect https://sys_api/ http://$host:$server_port/auth/; + proxy_redirect https://sys_api/ https://$host:$server_port/auth/; } - # 1. 认证中心 (IdentityServer4) 路由 - # 匹配所有认证相关的路径 - location ~ ^/(connect|Account)/ { - proxy_pass https://sys_api/; - proxy_ssl_verify off; # 关闭证书验证 + location /connect/ { + # 关键 1: 移除路径中的 /auth/ 前缀 + proxy_pass https://sys_api/connect/; # 末尾的 / 确保路径替换 + + proxy_ssl_server_name on; + proxy_ssl_session_reuse off; + proxy_ssl_verify off; + # 关键 2: 覆盖 Host 头,模拟 Vite 的 changeOrigin=true + proxy_set_header Host $proxy_host; # 设置为目标地址的 Host (192.168.1.100:19901) + + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host:$server_port; + proxy_set_header Authorization $http_authorization; # 传递 Authorization 头 + # 其他标准代理头 + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_redirect https://sys_api/connect/ https://$host:$server_port/connect/; + + } + location /Account/ { + # 关键 1: 移除路径中的 /auth/ 前缀 + proxy_pass https://sys_api/Account/; # 末尾的 / 确保路径替换 + + proxy_ssl_server_name on; + proxy_ssl_session_reuse off; + proxy_ssl_verify off; + # 关键 2: 覆盖 Host 头,模拟 Vite 的 changeOrigin=true + proxy_set_header Host $proxy_host; # 设置为目标地址的 Host (192.168.1.100:19901) + + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host:$server_port; + proxy_set_header Authorization $http_authorization; # 传递 Authorization 头 + # 其他标准代理头 + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_redirect https://sys_api/Account/ https://$host:$server_port/Account/; + } # 2. Sys API 路由 @@ -115,7 +148,7 @@ http { } # 3. Lmg API 路由 location /api/lmg/ { - proxy_pass http://lmg_api/api/; + proxy_pass https://lmg_api/api/; proxy_ssl_server_name on; proxy_ssl_session_reuse off; proxy_ssl_verify off;