aspose file tools*
The moose likes Tomcat and the fly likes Apache loadbalancing, mod_rewrite, mod_proxy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Apache loadbalancing, mod_rewrite, mod_proxy" Watch "Apache loadbalancing, mod_rewrite, mod_proxy" New topic

Apache loadbalancing, mod_rewrite, mod_proxy

Deyan Sultov
Ranch Hand

Joined: Jul 01, 2002
Posts: 32
I have 3 tomcat servers running on different machines and Apache server running on another machine. I want to make Apache
reverseproxing and loadbalancing this backend servers.
What I have done:
1. In Apache's httpd.conf:
<VirtualHost _default_:80>
RewriteEngine on
RewriteMap server rnd:/rewrite/rproxy.conf
RewriteRule ^/(.*)$ to://${server:web|tomcat_1:8080}/somecontext
RewriteRule ^to://([^/]+)/(.*) http://$1/$2 [P,L]
RewriteRule .* - [F]
#ProxyRequests On
#ProxyPassReverse / http://myserver:8080/somecontext/
#ProxyPassReverse / http://otherserver:8080/somecontext/
#ProxyPassReverse / http://someotherserver:8080/somecontext/
2. In rproxy.conf
www myserver:8080|otherserver:8080|someotherserver:8080
What I want:
1. When type in to be dispatched to one of the the backend servers.
The above mention code works fine. When I type I received
http://myserver:8080/somecontext or
http://otherserver:8080/somecontext or
2.The real backend server hostname to be masked to
Unfortunately I can not achive this. If uncomment the ProxyPassReverse directives Apache enters recursion. - > gets rewrited to http://myserver:8080/jmx-console which is ProxyPassed to
.. and so on..

What will happen if eventually I succeed with Rewriting, then sessions will be lost.
Can someone help me with this problems?
Thanks in advance
Deyan Sultov
Ranch Hand

Joined: Jul 01, 2002
Posts: 32
Ok. I find solution for rewriting:
in httpd.conf
<VirtualHost _default_:80>
RewriteEngine on
RewriteLog logs/proxy_rewrite.log
RewriteLogLevel 9
RewriteMap server rnd:rproxy.conf
RewriteRule^to://([^/]+)/(.*) http:// $1/$2[P,L]
ProxyPassReverse / http://server_1:8080/
ProxyPassReverse / http://server2:8080/
where rproxy.conf contains:
www server_1:8080|server_2:8080
but still I can not find the solutions with sessions. Each time mod_rewrite + rnd dispatches to a new server where no session received by previos login exist.Anyone can help?
Is it possible at all loadbalancing of servlet/jsp site to be done with Apache + mod_proxy + mod_rewrite?
[ July 10, 2003: Message edited by: Deyan Sultov ]
I agree. Here's the link:
subject: Apache loadbalancing, mod_rewrite, mod_proxy