【问题标题】:How to load balance and redirect with haproxy如何使用 haproxy 进行负载平衡和重定向
【发布时间】:2015-10-24 02:17:29
【问题描述】:
两台服务器上的内容都位于http://localhost:88/web/portal
我已经使用以下配置块配置了 haproxy
listen webfarm 0.0.0.0:8080
mode http
stats enable
stats uri /haproxy?stats
balance roundrobin
option httpclose
option forwardfor
server webserver01 192.168.1.10:88 check
server webserver02 192.168.1.20:88 check
如何让 haproxy 进一步重定向到目录?我试图通过 apache 在本地进行重定向,但我得到的只是循环。
【问题讨论】:
标签:
redirect
load-balancing
haproxy
【解决方案1】:
这是未经测试的,但您可能正在寻找类似的东西:
frontend my_frontend
mode http
bind *:8080
stats enable
stats uri /haproxy?stats
default_backend my_backend
backend my_backend
balance roundrobin
option httpclose
option forwardfor
reqrep ^(.*) /web/portal\1
server webserver01 192.168.1.10:88 check
server webserver02 192.168.1.20:88 check
关键更改是reqrep 行,它接收请求的uri 并在其前面加上/web/portal(至少应该如此)。
抱歉,它与您的示例格式不同,但我只是从我的一些配置中复制并更改了它。让我知道这是否适合您的情况。