【发布时间】:2019-09-07 03:40:46
【问题描述】:
如何在我的回复中重定向我的所有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即
change the spec.rules.host.paths.path from /odin/?(.*) to/(odin/.*)
上面的建议可能有错别字。我认为应该http 而不是host。
【问题讨论】:
标签: nginx kubernetes nginx-ingress