负载Apache和Tomcat平衡与URL重定向结合 [英] Load balancing with Apache and Tomcat combined with URL redirect

查看:196
本文介绍了负载Apache和Tomcat平衡与URL重定向结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个Apache服务器和两个Tomcat的服务器。他们使用的mod_jk模块相连。和负载分担。所有的请求将被重定向到负载均衡器,在httpd.conf:

I now have one Apache server and two Tomcat servers. They are connected using mod_jk module. And the load balancing is configured. All request will be redirected to the loadbalancer, in httpd.conf:

JKMount /* controller

该控制器是负载均衡器,以及工作的Tomcat服务器worker1,worker2。

The controller is the loadbalancer, and the working tomcat servers are worker1, worker2.

的问题在于,除了自动负载调度,我还需要一个url匹配重定向。 Speicifically,对于 http://www.example.com/test1/index.html应该去worker1(Tomcat)的,和 http://www.example.com/test2/index .HTML 去worker2。
然而,在这两个worker1和worker2,应用结构的webapps /测试/结构。

The problem is that, in addition to the automatic load dispatch, I also need a url matching redirection. Speicifically, the request for http://www.example.com/test1/index.html should go to worker1 (Tomcat), and http://www.example.com/test2/index.html go to worker2. However, in both worker1 and worker2, the application structure is webapps/test/ structure.

我可以使用mod_jk的URL映射派遣/ TEST1 /为worker1和/ TEST2 /到worker2,但路径为/ TEST1 /和/ test2的/不是/测试/。同时,如果我使用Apache redirectMatch或URL重写更改/ TEST1 /(/测试2 /)到/测试/时,mod_jk的不会调度的URL不同的工人,现在,因为它们具有相同的路径。

I can use the mod_jk url mapping to dispatch /test1/ to worker1 and /test2/ to worker2, but the PATH will be /test1/ and /test2/ not /test/. Meanwhile, if I use the apache redirectMatch or url rewrite to change the /test1/(/test2/) to /test/, the mod_jk will not dispatch the url to the different worker now, since they have the same PATH.

该如何应对这种局面?

推荐答案

您需要使应用程序在Tomcat的根应用程序。您可以通过添加一个META-INF / context.xml中到您的应用程序有以下这样做:

You need to make the application a root application in Tomcat. You can do this by adding a META-INF/context.xml to your app with the following:

<Context path="/"/>

我建议你从webapps目录中删除其他应用程序。然后,你需要改变你的应用程序的web.xml这样的servlet(S)现在映射到相应的URL与适当的上下文:

I'd suggest you remove other apps from the webapps directory. Then you need to alter your apps web.xml so the servlet(s) are now mapped to the appropriate url with the appropriate contexts:

<servlet-mapping>
    <servlet-name>TestApp</servlet-name>
    <url-pattern>/test</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>TestApp</servlet-name>
    <url-pattern>/test1</url-pattern>
</servlet-mapping>

第二JVM的应用程序将需要的URL模式/ test2的替代。对于Apache / Tomcat的连接,我用mod_ajp而非mod_jk的。下面是你需要什么的Apache mod_ajp:

The app in the second JVM would need the url-pattern /test2 instead. For Apache/Tomcat connection I use mod_ajp rather than mod_jk. Here is what you'd need in Apache for mod_ajp:

<Proxy balancer://cluster>
    BalancerMember ajp://127.0.0.1:8015 route=ajp13_node1
    BalancerMember ajp://127.0.0.1:8016 route=ajp13_node2
</Proxy>
<Location "/test">
    ProxyPass balancer://cluster/test stickysession=JSESSIONID
</Location>
<Location "/test1">
    ProxyPass ajp://127.0.0.1:8015/test1
</Location>
<Location "/test2">
    ProxyPass ajp://127.0.0.1:8016/test2
</Location>

这是假设的AJP连接器在8015监听第二首JVM和8016。

This is assuming the AJP connector is listening on 8015 for the first JVM and 8016 for the second.

这篇关于负载Apache和Tomcat平衡与URL重定向结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆