Click to See Complete Forum and Search --> : Apache loadbalancing, mod_rewrite, mod_proxy


dsultov
07-10-2003, 05:10 AM
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:808 0



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

dsultov
07-10-2003, 12:09 PM
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]
ProxyRequests On
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. Anyone help?