首页 文章

Apache ProxyPass到2个具有相同URI的不同tomcat服务器

提问于
浏览
0

我有两台服务器,带有apache http server(2.4.9) . 我有两台运行tomcat 7.0.39的服务器 . 最终我需要在2之间加载 balancer ,但现在我只是想让这个ProxyPass配置工作 .

我在2个apache servers- example.com上有一个url . 它们是负载 balancer 的 . 负载 balancer 到位,没有问题 .

我有2个应用程序,每个tomcat服务器上有1个 . 每个tomcat服务器都有2个运行tomcat的实例 - 每个实例位于不同的端口上 . 他们使用完全相同的uri运行一个非常相似的应用程序 .

我需要重定向:

example.com/site1到example.com/app(适用于app1)

example.com/site2到example.com/app(适用于app2)

我可以轻松地将其重定向到仅1个应用程序:

ProxyPass / app / AppSrv:8080 / app /

ProxyPassReverse / app / http://example.com/app/

我可以到页面,登录,没问题 . 仅适用于单一应用 .

当我为两个应用程序设置配置时,我也可以在这样配置时进入两个应用程序的登录页面:

ProxyPass / site1 / AppSrv:8080 / app

ProxyPassReserve / app /

ProxyPass / site2 / AppSrv:8081 / app

ProxyPassReverse / app /

两个网址都提供了tomcat应用程序登录页面 . 但是在此之后都没有工作 - 他们失败了 . uri读取'site1'(或'site2')而不是'app' . 我不能登入 .

该应用程序需要uri'/ app /'作为基础uri才能运行 .

应用程序正在侦听不同的端口,但具有相同的uri . 如何将uri保留在URL中,但更改它以便应用程序响应?

最终我必须 balancer 这一点,但我之前已经做过了 . 这是我遇到困难的部分 .

1 回答

  • 0

    好的,我终于解决了这个问题 . 我不得不修改 Headers .

    ProxyPass /site1/ balancer://example.com/app/ 
    
    ProxyPass /site2/ balancer://example.com/app/ 
    
    <Location /site1>
    ProxyPassReverse /app
    ProxyPassReverseCookiePath /app /site1
    Header edit Location ^(https?://)?example.com/app/ /site1/
    </Location>
    
    <Location /site2>
    ProxyPassReverse /app
    ProxyPassReverseCookiePath /app /site2
    Header edit Location ^(https?://)?example.com/app/ /site2/
    </Location>
    

相关问题