I have a haproxy configuration like this:
frontend api
mode http
default_backend tomcat
backend tomcat
mode http
balance roundrobin
option httpchk HEAD / HTTP/1.0
server tomcat1 10.0.0.1:1234 weight 1 maxconn 512 check
server tomcat2 10.0.0.2:1234 weight 1 maxconn 512 check
This works, but the urls have to be like: http://api.example.com/project/api/get-something and we’d like to set haproxy somehow so that the url http://api.example.com/api/get-something will get to the same result.
I tried to add the url prefix:
server tomcat1 10.0.0.1:1234/project/ weight 1 maxconn 512 check
server tomcat2 10.0.0.2:1234/project/ weight 1 maxconn 512 check
but it’s not supported. Is there a way I can do this only using haproxy? I don’t want to set up an apache just to proxy for tomcat.
From my understanding, you want to rewrite
/api/to/project/.If yes, then add the line below to your backend configuration:
Note that you’ll have to enable the option http-server-close on both the frontend and the server for the rewrite rule to be applied to all the requests in a session.