如何使用 Istio 虚拟服务在 url https 之间重定向 301

How to do redirect 301 between url https using Istio Virtual Service

提问人:William Miranda de Jesus 提问时间:9/29/2023 最后编辑:William Miranda de Jesus 更新时间:9/29/2023 访问量:84

问:

我正在尝试使用 Istio 的网关和 VirtualService 对某些请求执行 301 重定向。我已经完成了所有工作,如果请求是通过 HTTP 进行的,它可以完美运行,但它不适用于 HTTPS。

场景如下:我有一个地址 https://www.myhost.com/oldpath,我想将其重定向到 https://myhost.com/newpath。我有几个 URL 需要对没有“www.”的主机进行此更改,并且还更改了路径。

请注意,在我的网关中,我使用的是 ManagedCertificate,它在 Google Cloud Platform 中生成了证书。由于我无法创建密钥来传递网关的 tls 属性,因此我将其配置为 PASSTHROUGH。

当我的证书没有带有“www.”的域时,它起作用了。但是,当我创建包含带和不带“www.”的域的 ManagedCertificate 时,重定向停止工作。 以下是我的文件。

#managed-certificate-file

apiVersion: networking.gke.io/v1
kind: ManagedCertificate
metadata:
  name: managed-cert
spec:
  domains:
    - myhost.com
    - www.myhost.com    
---
#ingress-file
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: my-external-ip-gcp
    kubernetes.io/ingress.class: "gce"
    kubernetes.io/ingress.allow-http: "true"
    networking.gke.io/v1beta1.FrontendConfig: my-frontend-config
spec:
  defaultBackend:
    service:
      name: my-important-service
      port:
        name: http
---

#frontend-config-file

apiVersion: networking.gke.io/v1beta1
kind: FrontendConfig
metadata:
  name: my-frontend-config
spec:
  sslPolicy: my-ssl-policy
  redirectToHttps:
    enabled: false       
---
#gateway-file

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: my-gateway
spec:
  selector:
    istio: ingressgateway 
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
  - port:
      number: 443
      name: https
      protocol: HTTPS
    hosts:
    - "*"
    tls:
      mode: PASSTHROUGH
---
#virtual-service file

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: myhost-redirect
spec:
  hosts:
    - "www.myhost.com"
  gateways:
    - my-gateway

  http:
    - match:
        - uri:
            exact: /register
      redirect:
        uri: /sign-up
        authority: myhost.com
        scheme: "https"

    - match:
        - uri:
            exact: /get-my-password
      redirect:
        uri: /password-reset
        authority: myhost.com
        scheme: "https"
SSL Istio http-status-code-301 http-redirect istio-gateway

评论


答: 暂无答案