haproxy – 路由请求并保持相同的基本URL

我是haproxy的新手,我正努力尝试configuration它。

我想要的是:

  1. 在浏览器中input:proxy.company.com/Test/App
  2. 请haproxy在webapp01.company.com/Test/App和webapp02.company.com/Test/App之间平衡请求
  3. 保持基本URL proxy.company.com/Test/App

我到目前为止:我有两个网站设置:

  1. webapp01.company.com/Test/App
  2. webapp02.company.com/Test/App

这两个工作,当我浏览到每个单独我得到一个屏幕与服务请求服务器(WebApp01或WebApp02)的名称。

但是,当我去proxy.company.com/Test/App我得到一个404错误。 我期望的请求被路由到webapp01或webapp02,我希望看到服务器请求的服务器的名称。

这是我目前的configuration:

global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy user haproxy group haproxy daemon defaults log global mode http option httplog option dontlognull contimeout 5000 clitimeout 50000 srvtimeout 50000 errorfile 400 /etc/haproxy/errors/400.http errorfile 403 /etc/haproxy/errors/403.http errorfile 408 /etc/haproxy/errors/408.http errorfile 500 /etc/haproxy/errors/500.http errorfile 502 /etc/haproxy/errors/502.http errorfile 503 /etc/haproxy/errors/503.http errorfile 504 /etc/haproxy/errors/504.http frontend proxy.company.com bind :80 acl test_app path_end -i /Test/App use_backend srvs_test if test_app backend srvs_test balance roundrobin server webapp01 webapp01.company.com:80 check server webapp02 webapp02.company.com:80 check 

如果我将后端configuration更改为:

 backend srvs_test balance roundrobin redirect location http://webapp01.company.com/Test/App 

但是,如果我键入proxy.company.com/Test/App,则会redirect到webapp01.company.com/Test/App。 基本url已更改,我希望它保持proxy.company.com/Test/App

可能吗? 如何改变configuration,以允许我想要的?

反向代理将默认重写位置标题,因此不需要这样做。

使用path_beg而不是path_end

我认为你的configuration太小了。 当您proxy.company.com时会发生什么? 你缺less一个default_backend

此外,代理的整个想法是,你不必向世界公开webapp01和02。 不需要像这些DNS条目那样向他们提供外部IP。 只需使用从您的代理可到达的内部。

尝试像这样:

 frontend proxy.company.com *:80 acl test_app path_beg -i /Test/App use_backend srvs_test if test_app default_backend default backend srvs_test balance roundrobin server webapp01 webapp01.company.com:80 check server webapp02 webapp02.company.com:80 check backend default server localhost:80 check