发布于 1 个月前
发布于 1 个月前
太初
更新于 1 个月前
0
0
在配置 Nginx 代理雷池管理面板时,我使用了以下配置:
1 2upstream safeline-mgt { 3 server 10.0.8.9:9443; 4 } 5 6 server { 7 listen 80; 8location /safeline/ { 9 proxy_http_version 1.1; 10 proxy_set_header Upgrade $http_upgrade; 11 proxy_set_header Connection $connection_upgrade; 12 proxy_set_header Host $http_host; 13 proxy_pass https://safeline-mgt/; 14 proxy_ssl_verify off; 15 16 # 替换响应头中的路径 17 proxy_redirect default; 18 proxy_redirect / /safeline/; 19 20 # 替换响应内容中的路径 21 sub_filter_types *; 22 sub_filter_once off; 23 sub_filter 'href="/' 'href="/safeline/'; 24 sub_filter 'src="/' 'src="/safeline/'; 25 sub_filter 'action="/' 'action="/safeline/'; 26 sub_filter 'content="/' 'content="/safeline/'; 27 sub_filter 'url(/' 'url(/safeline/'; 28 sub_filter 'url("/' 'url("/safeline/'; 29 sub_filter "url('/" "url('/safeline/"; 30 31 # 确保子过滤器生效 32 proxy_set_header Accept-Encoding ""; 33}
在只使用此配置时,可以成功显示雷池的登录页面,代理的功能正常。
当我添加如下的 /api
代理配置后,遇到了自动重定向的问题:
1location /api { 2 proxy_set_header Host $http_host; 3 proxy_set_header X-Real-IP $remote_addr; 4 proxy_set_header REMOTE-HOST $remote_addr; 5 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 6 proxy_pass https://safeline-mgt; 7 proxy_ssl_verify off; 8}
在 /api
配置启用后,页面会自动重定向到根目录,导致无法正常访问 /api
下的接口。
希望能够在 /safeline/
路径下正常访问管理面板,同时在 /api
路径下代理 API 请求,但避免发生自动重定向问题。
请问雷池是否在应用前端做了什么控制指定跳转到根路径?
这个是我服务器上docker容器运行情况:
1CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 20e4e074956d7 nginx:latest "/docker-entrypoint.…" 6 days ago Up 36 minutes 0.0.0.0:81->80/tcp, [::]:81->80/tcp, 0.0.0.0:448->443/tcp, [::]:448->443/tcp taichu-nginx 3ab8cfae85d91 swr.cn-east-3.myhuaweicloud.com/chaitin-safeline/safeline-luigi:latest "/bin/sh -c /app/lui…" 2 weeks ago Up 2 weeks 80/tcp safeline-luigi 410dfebc82a88 swr.cn-east-3.myhuaweicloud.com/chaitin-safeline/safeline-bridge:latest "/app/bridge serve -…" 2 weeks ago Up 2 weeks safeline-bridge 581db849bd494 swr.cn-east-3.myhuaweicloud.com/chaitin-safeline/safeline-mgt:latest "/docker-entrypoint.…" 2 weeks ago Up 2 weeks (healthy) 80/tcp, 0.0.0.0:9443->1443/tcp, [::]:9443->1443/tcp safeline-mgt 6b80f653cf38c swr.cn-east-3.myhuaweicloud.com/chaitin-safeline/safeline-tengine:latest "entrypoint.sh nginx…" 2 weeks ago Up 2 weeks safeline-tengine 78089ec7d2e4e swr.cn-east-3.myhuaweicloud.com/chaitin-safeline/safeline-chaos:latest "./entrypoint.sh" 2 weeks ago Up 2 weeks 9000/tcp safeline-chaos 82f4dc7ce2c55 swr.cn-east-3.myhuaweicloud.com/chaitin-safeline/safeline-fvm:latest "./fvm /app/config.y…" 2 weeks ago Up 2 weeks safeline-fvm 99fb09b4ba680 swr.cn-east-3.myhuaweicloud.com/chaitin-safeline/safeline-postgres:15.2 "docker-entrypoint.s…" 2 weeks ago Up 2 weeks (healthy) 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp safeline-pg 10c9e94975e9fe swr.cn-east-3.myhuaweicloud.com/chaitin-safeline/safeline-detector:latest "/detector/entrypoin…" 2 weeks ago Up 2 weeks (healthy) 8000-8001/tcp
齐天大圣孙悟空
更新于 1 个月前
1
0
很难实现这个效果。。。。
调用 API 的代码都是写在 js 里的,你还得去替换 js 里的路径,而且很多 API 的路径是动态拼接出来的,难上加难。
太初
更新于 1 个月前
感谢回答,我这边已经了解情况,如果没法替代的话,我打算后面转而使用子域名的方式进行替换,非常感谢