Istio 将非 www 流量重定向到 www



我正在使用 istioingress gateway。如何将非 www 流量重定向到 www?

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: my-gateway
namespace: some-config-namespace
spec:
selector:
app: my-gateway-controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- uk.bookinfo.com
- eu.bookinfo.com
- www.uk.bookinfo.com
- www.eu.bookinfo.com
tls:
httpsRedirect: true # sends 301 redirect for http requests
- port:
number: 443
name: https-443
protocol: HTTPS
hosts:
- uk.bookinfo.com
- eu.bookinfo.com
- www.uk.bookinfo.com
- www.eu.bookinfo.com
tls:
mode: SIMPLE # enables HTTPS on this port
serverCertificate: /etc/certs/servercert.pem
privateKey: /etc/certs/privatekey.pem

目前,我可以使用两个端点访问该网站。但是,我想将所有流量从非 www 重定向到 www。

Istio 网关接收流量,从那里的路由将由 VirtualService 配置处理。对于您的非 www 到 www 流量路由,在 Istio 论坛中提出了同样的问题,因此可能对您有所帮助。

https://discuss.istio.io/t/simply-redirecting-non-www-to-www/3370

至于获取所有流量,您可能需要在网关配置的hosts定义中使用通配符(参考: https://istio.io/docs/reference/config/networking/gateway/#Server(。

你试过redirectIstio 的功能吗?

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: server-vs
spec:
hosts:
- mysite.com
gateways:
- my-gateway
http:
- match:
- uri:
exact: /
redirect:
uri: /
authority: www.mysite.com

您也可以在DNS级别完成重定向。但我认为一些域名提供商不支持它。例如,戈达迪就是这样做的。

最新更新