0

I have multiple web services running on the same machine on different ports, and I would like to use HAproxy to connect to them through different URLs

For example, localhost/app1 should go to localhost:1234, and localhost/app2 should go to localhost:5678

I have done this by using

...
use_backend backend_app1 if { path_beg -i /app1 }
...

backend backend_app1
   server autosupport localhost:1234

However now if i go to say localhost/app1/my_page.html, my web server complains since it does not know what /app1/my_page.html is, it only knows what /my_page.html is

I've fixed that by just removing the /app1 with a regsub:

backend backend_app1
   http-request set-uri %[url,regsub(^/app1,/,)]
   server autosupport localhost:1234

This is now able to load whatever is at localhost/app1/my_page.html

My problem now is that my_page.html may try to load other files, such as an image, using a relative URI. For example <img src='/my_image'>

This goes to localhost/my_image. I need this to go to localhost/app1/my_image, and I can not change the pages them selves to use absolute URLs

I have tried setting the content-base header, but that did not seem to work. I have also tried playing around with cookies and the referrer header, but I have not found anything that has worked.

If this is not possible with HAproxy, I am open to using something else.

Kevin P
  • 1
  • 1

0 Answers0