When using HAProxy for virtual hosting, I can see how to use the Host from the header at the front end to decide what backend to route to. However, is it possible to make the back end be a URL which includes a path (not unlike what you would do with apache or nginx when setting up virtual hosting).
http://www.techrawr.com/tag/haproxy/ - shows most of it. But what if the back ends were on the one server but with backend1 and backend2 as the servers?
I think you're looking for something like this in order to balance to different servers based on the URL:
Source: Haproxy ACL for balance on URL request
The "server" directive in HAProxy supports a number of parameters, and one option is "redir" parameter. You can use it to send an HTTP 302 redirect back to the client - and have the client talk to the backend (this will not proxy though):
Example:
backend www_example_com
balance roundrobin
server Backend1 10.0.0.1:80 redir http:// www.example.com/backend1
server Backend2 10.0.0.1:80 redir http:// www.example.com/backend2
If only HA proxy has a public port then redirect to backend would not be a good solution For this you may want the ha proxy to do the work as it suppose to, altough I'm not sure if it is a good practice to modify the path depending on the result of the loadbalance.
I posted my solution to stackoverflow under a similar question, check it out for more information Detailed answer