【问题标题】:How to redirect with envoy proxy如何使用特使代理重定向
【发布时间】:2021-06-26 11:15:41
【问题描述】:

我们使用 envoy 代理作为入口 HTTP 代理。现在我们想要从https:/our_domain/ 重定向到https:/our_domain/static/index.html。 例如,到目前为止,我们所有的尝试都失败了

          routes:
          - match:
              path: "/"
            redirect: { path_redirect: "/static/index.html" }
          - match:
              prefix: "/"
            route:
              prefix_rewrite: "/"
              cluster: our_cluster

如何为此用例配置路由?请不要 Lua 解决方案。

【问题讨论】:

    标签: http-redirect envoyproxy


    【解决方案1】:

    问题在于 envoy 代理位于 tls 终止代理之后。因此,重定向始终使用 http 方案,tls 终止代理不提供该方案。

    解决办法是

    https_redirect (bool) URL 的方案部分将与“https”交换。

    因此正确的路由必须是

          routes:
          - match:
              path: "/"
            redirect:
              https_redirect: true
              path_redirect: "/static/index.html"
          - match:
              prefix: "/"
            route:
              cluster: our_cluster
    

    【讨论】:

      【解决方案2】:

      前缀“/”匹配任何请求,所以你只是无休止地重定向。在 catch all one 前面设置一个匹配前缀“/static”的路由,并将其转发到上游集群以提供响应。 (对于静态文件,您也可以直接从 Envoy 提供它们。)

      【讨论】:

        【解决方案3】:
        - name: listener_http
            address:
              socket_address: 
                address: 0.0.0.0
                port_value: 80
          filter_chains:
            - filters:
              - name: envoy.http_connection_manager
                config: 
                  codec_type : auto 
                  stat_prefix: ingress_http
                  route_config:
                    virtual_hosts:
                    - name: backend
                      domains:
                      - "*"
                      routes:
                      - match:
                          prefix: "/"
                        redirect:
                          path_redirect: "/"
                          https_redirect: true
        
                  http_filters:
                  - name: envoy.router
                    config: {} 
        

        将此代码放在 https 部分的侦听器之前以重定向所有请求

        【讨论】:

        • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
        • 你应该在fileenvoy.yaml的listerner部分添加这段代码
        猜你喜欢
        • 1970-01-01
        • 2014-03-19
        • 2012-06-03
        • 2015-07-31
        • 1970-01-01
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多