Haproxy route and rewrite based on URI path

前端 未结 2 1337
盖世英雄少女心
盖世英雄少女心 2020-12-05 15:26

I am trying to setup an Haproxy to load balance requests on a few backends identified by the uri path. For example:

https://www.example.com/v1/catalog

2条回答
  •  再見小時候
    2020-12-05 15:56

    The answer above is a single fix that doesn't explain the root of the problem. The problem is that many assume we're parsing a complete URL or only the PATH component, when we're actually parsing/rewriting HTTP headers.

    For example:

    curl -iv https://stackoverflow.com/questions/24784517/haproxy-route-and-rewrite-based-on-uri-path
    *   Trying 151.101.65.69...
    > GET /questions/24784517/haproxy-route-and-rewrite-based-on-uri-path HTTP/1.1
    > Host: stackoverflow.com
    > User-Agent: curl/7.54.0
    > Accept: */*
    

    The goal is to rewrite GET /some_path HTTP/1.1 to GET /some_other_path HTTP/1.1

    I want to clarify that the solution above works because it takes into account the HTTP verb in the match and replace. ^([^\ ]\*)\ (.*) to capture the verb and use it in the replacement pattern. \1 \2

提交回复
热议问题