gpt4 book ai didi

nginx - 建立相对于新路径的链接

转载 作者:行者123 更新时间:2023-12-02 11:37:11 25 4
gpt4 key购买 nike

如何重定向我所有的 hrefs在我对新道路的回应中。例如,我的入口文件是

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-odin
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1

spec:
rules:
- http:
paths:
- path: /odin/?(.*)
backend:
serviceName: flask-app-tutorial
servicePort: 8080

当我访问 https://mysite/odin 的页面时.它工作并返回响应:

HTML 响应是:
<html>
..
<body>
<div>
<a href="/v0/index">Home</a>
<a href="/v0/login">Login</a>
</div>

</body>
</html>

但是,如您所见,相关链接类似于 <a href="/v0/index">Home</a> .如果我点击它,它将不起作用,因为没有像 http://mysite/v0/index 这样的链接。 .如果我点击链接,我希望它转到 http://mysite/odin/v0/index .是否可以通过修改响应中的链接来获得 odin或者如果我点击它,它会查看源网址,即 http://mysite/odin并指导它相对于那个?
Nginx Version: 1.15.10
ingress-nginx: 0.24.0

到目前为止,我已经尝试了以下方法。
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header Accept-Encoding ""; #disable compression
sub_filter '<head>' '<head> <base href="/odin/">';


nginx.ingress.kubernetes.io/add-base-url: ":true"
nginx.ingress.kubernetes.io/app-root: /odin

nginx.ingress.kubernetes.io/use-regex: "true"

我也试过 this IE。
 change the spec.rules.host.paths.path from /odin/?(.*) to/(odin/.*)

上面的建议可能有错别字。我觉得应该 http而不是 host .

最佳答案

我有一个类似的问题,并受到你的问题的启发,我找到了一个对我有用的解决方案。
您的注释应该像这样工作:

nginx.ingress.kubernetes.io/configuration-snippet: |
sub_filter_once on;
sub_filter '<base href="/"' '<base href="/odin/"';

如您所见, sub_filter 现在已启用,我使用 base 而不是 head。

关于nginx - 建立相对于新路径的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55718282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com