移除要求中的雙斜線

問題:要求中的雙斜線可能會導致要求無法解析

任何含有連續兩個斜線 (或更多) 的要求都可能導致 404 錯誤。例如 /hello//world/。這個範例的問題是 helloworld 之間的「//」。

解決方案:篩選雙斜線

將設定套用至 Istio ingress,以便篩選要求中的雙斜線並加以取代。

  1. 建立名為 apigee-merge-slash-filter.yaml 的新設定檔。
  2. 將下列內容貼到檔案中:
    apiVersion: networking.istio.io/v1alpha3
    kind: EnvoyFilter
    metadata:
      name: apigee-merge-slashes
      namespace: istio-system
    spec:
      workloadSelector:
        labels:
          app: istio-ingressgateway
      configPatches:
      - applyTo: NETWORK_FILTER # http connection manager is a filter in Envoy
        match:
          context: GATEWAY
          listener:
            filterChain:
              filter:
                name: "envoy.http_connection_manager"
        patch:
          operation: MERGE
          value:
            typed_config:
              "@type": "type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager"
              merge_slashes: true
  3. 使用下列指令套用設定:
    kubectl apply -f apigee-merge-slash-filter.yaml