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
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Apache loadbalancing, mod_rewrite, mod_proxy" Watch "Apache loadbalancing, mod_rewrite, mod_proxy" New topic
Author

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>
ServerName www.myserver.com
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/
</VirtualHost>
2. In rproxy.conf
www myserver:8080|otherserver:8080|someotherserver:8080
What I want:
==============
1. When type in www.myserver.com to be dispatched to one of the the backend servers.
The above mention code works fine. When I type www.myserver.com I received
http://myserver:8080/somecontext or
http://otherserver:8080/somecontext or
http://someotherserver:8080/somecontext
2.The real backend server hostname to be masked to www.myserver.com.
Unfortunately I can not achive this. If uncomment the ProxyPassReverse directives Apache enters recursion.
http://www.myserver.com - > gets rewrited to http://myserver:8080/jmx-console which is ProxyPassed to http://www.myserver.com
.. and so on..

Issues:
============
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^(http|https)://.*-[F]
RewriteRule^/(.*)$to://${server:web}/$1
RewriteRule^to://([^/]+)/(.*) http:// $1/$2[P,L]
RewriteRule.*-[F]
ProxyRequestsOn
ProxyPassReverse / http://server_1:8080/
ProxyPassReverse / http://server2:8080/
</VirtualHost>
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 ]
 
Consider Paul's rocket mass heater.
 
subject: Apache loadbalancing, mod_rewrite, mod_proxy