How can I proxy on specific context path?

1

We are currently relocating an application that uses context to select "profiles" (define app properties and JDBC connection string)

For now, the URL is this kind: https://www.foo.com/test/company/profil-name/ Then you are redirected to https://www.foo.com/test/company/profil-name/web/online But there is also other stuff like api contexts: https://www.foo.com/api/profile-name/

I know that the current application is using apache + haproxy on frontend and backend:

Web => apache => local haproxy => backend haproxy => application backend

My problem is that I'm trying to reproduce the same config here, but the proxy doesn't work well (I test with a modified host file):

https://www.foo.com/test/company/profil-name/ redirects to https://www.foo.com/web/test/company/profil-name/online

It's like the initial context was taken as option string by the application.

I made some combination on haproxy / apache config and when I use a simple reverse proxy configuration without profiles context selection, it's working (except that I have only one profile...) :

https://www.foo.com/web/online

Did you already have these kind of behavior ? I use haproxy 1.8 and apache httpd 2.4.

Here is what my haproxy config looks like:

frontend default
        bind *:80
        capture request header X-Forwarded-For len 15
        acl rest_url path /api
        acl rest_url path_beg /api/
        acl app1_profile path_beg /test/company/app1
        acl app2_profile path_beg /test/company/app2

        use_backend app3 if rest_url 
        use_backend app1 if app1_profile
        use_backend app2 if app2_profile

backend app1
        cookie SERVERID insert indirect nocache httponly
        #http-request redirect location http://test.domain.com%[url,regsub(^/web/,/test/company/app1/web/,)]%[query] if { path_beg /web/ }
        #http-request set-var(txn.path) path
        #http-response redirect location https://test.domain.com/test/company/app1/var(txn.path) if ! { path_beg /test/ }
        #reqirep ^Host:\ .*$ Host:https://test.domain.com/test/company/app1/
        server app1_backend 192.168.10.15:80

Apache config:

   ProxyRequests On
   ProxyPreserveHost On

   <Location /test/company/app1/>
      ProxyPass http://localhost:80/
      ProxyPassReverse http://localhost:80/
   </Location>

I have spent hours to try to have a working config, but it still doesn't work. I hope that someone could help me.

Thanks,
Sebastian

Sébastien Simonek

Posted 2019-05-27T09:22:28.800

Reputation: 11

No answers