【发布时间】:2023-03-07 03:07:01
【问题描述】:
我们想在 site.abc.com 中加载 example.xyz.com。最好的方法是将所有请求从 site.abc.com 重定向/重写到 example.xyz.com。但是,我们不希望更改浏览器 URL。 From this similar SO problem 我们知道我们需要一个如下的 Nginx 位置配置
server {
servername site.abc.com;
listen 80;
....
....
....
....
location / {
proxy_pass http://example.xyz.com;
rewrite /(.*)$ /$1 break;
}
}
但是,我不确定如何在 Kubernetes ingress-nginx 中创建类似的规则,因为它为每个规则添加了 proxy_pass,这会阻止我们在 nginx.ingress.kubernetes.io/configuration-snippet: 注释中添加 proxy_pass 配置。
还在 ingress 中提供nginx.ingress.kubernetes.io/rewrite-target: http://example.xyz.com/$1 注释,如下所示,重定向到 example.xyz.com 而不是在 site.abc 中加载 example.xyz.com .com.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: http://example.xyz.com/$1
name: url-rewrite
namespace: default
spec:
rules:
- host: site.abc.com
http:
paths:
- backend:
service:
name: service
port:
number: 80
path: /(.*)
pathType: ImplementationSpecific
在这种情况下,我们如何在 site.abc.com 中加载 example.xyz.com 而不会使用 ingress-nginx 更改浏览器 URL?
【问题讨论】:
-
你好@Mani。你有没有碰巧看到this solution?
-
@WytrzymałyWiktor 我试过了,它正在工作。谢谢。
-
@WytrzymałyWiktor 对答案中提到的 SSL 重定向问题有何想法?
-
你好@Mani。很高兴它有帮助。至于 SSL 重定向,为了清楚起见,我建议提出一个单独的问题。社区可以更轻松地帮助您。
标签: url kubernetes url-rewriting kubernetes-ingress nginx-ingress