I'm new to haproxy and I'm struggling a little bit trying to configure it.
What I want:
- Type in the browser: proxy.company.com/Test/App
- Have haproxy balance the request between webapp01.company.com/Test/App and
webapp02.company.com/Test/App - Keep the base URL proxy.company.com/Test/App
What I have so far:
I have two websites setup:
- webapp01.company.com/Test/App
- webapp02.company.com/Test/App
Both work and when I browse to each individually I get a screen with the name of the server that served the request (WebApp01 or WebApp02).
However, when I go to proxy.company.com/Test/App I get a 404 error. I expect the request to be routed to webapp01 or webapp02 and I expect to see the name of the server serving the request.
Here's my current 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
If I change the backend configuration to this:
backend srvs_test
balance roundrobin
redirect location http://webapp01.company.com/Test/App
It works, however, if I type proxy.company.com/Test/App I'm redirected to webapp01.company.com/Test/App. The base URL is changed and I want it to remain proxy.company.com/Test/App
Is it possible? How chan I change the configuration to allow what I want?
Best Answer
A reverse proxy will by default rewrite the Location header so there is no need for to to do that.
Use
path_beg
instead ofpath_end
.I think your config is too minimal. What happens when you hit
proxy.company.com
? You are missing adefault_backend
.Also, the whole idea of the proxy is that you don't have to expose webapp01 and 02 to the world. No need to give them external IPs as your example shows with those DNS entries. Just use the internal ones reachable from your proxy.
Try something like: