如何代理特定的上下文路徑?

如何代理特定的上下文路徑?

我們目前正在重新定位一個使用上下文來選擇「設定檔」的應用程式(定義應用程式屬性和 JDBC 連接字串)

目前,URL 是這樣的:https://www.foo.com/test/company/profile-name/ 然後您將被重定向到https://www.foo.com/test/company/profile-name/web/online 但還有其他東西,例如 api 上下文: https://www.foo.com/api/profile-name/

我知道目前的應用程式在前端和後端使用 apache + haproxy:

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

我的問題是,我試圖在這裡重現相同的配置,但代理程式不能很好地工作(我使用修改後的主機文件進行測試):

https://www.foo.com/test/company/profile-name/重定向到https://www.foo.com/web/test/company/profil-name/online

這就像應用程式將初始上下文作為選項字串。

我在 haproxy / apache 配置上做了一些組合,當我使用簡單的反向代理配置而不選擇配置文件上下文時,它正在工作(除了我只有一個配置文件...):

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

你是否已經有過這樣的行為呢?我使用 haproxy 1.8 和 apache httpd 2.4。

我的 haproxy 配置如下:

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

阿帕契配置:

   ProxyRequests On
   ProxyPreserveHost On

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

我花了幾個小時嘗試建立一個有效的配置,但它仍然不起作用。我希望有人能幫助我。

謝謝,
塞巴斯蒂安

相關內容