Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Rewrite rule for apache load balancer


Go to End


3 Posts   5243 Views

Avatar
levinng

Community Member, 2 Posts

22 May 2010 at 5:09am

Edited: 24/05/2010 8:57pm

I have 1 apache load balancer www.mydomain.com setup for 2 underlying web server www1, www2. However I can't get it rewrite the URL to www. The setup is fine for static html page. Anyone have experience on that. Thank you very much!!

Load balancer setup as below

ProxyRequests Off
ProxyPass / balancer://cluster/ stickysession=BALANCEID nofailover=On
ProxyPassReverse / http://www1.mydomain.com/
ProxyPassReverse / http://www2.mydomain.com/
<Proxy balancer://cluster>
BalancerMember http://www1.mydomain.com/ route=www1
BalancerMember http://www2.mydomain.com/ route=www2
ProxySet lbmethod=byrequests
</Proxy>

web server setup as below

<VirtualHost 192.168.1.1:80>
ServerName www1.mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "/u01/mydomain/wwwroot/www"
CustomLog /u01/mydomain.com/logs/www1.mydomain-access.log combined
ErrorLog /u01/mydomain.com/logs/www1.mydomain-error.log
RewriteEngine On
RewriteRule .* - [CO=BALANCEID:balancer.www1:.www.mydomain.com]
<Directory "/u01/mydomain.com/wwwroot/www/">
AllowOverRide All
</Directory>
</VirtualHost>

<VirtualHost 192.168.1.2:80>
ServerName www2.mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "/u01/mydomain/wwwroot/www"
CustomLog /u01/mydomain.com/logs/www2.mydomain-access.log combined
ErrorLog /u01/mydomain.com/logs/www1.mydomain-error.log
RewriteEngine On
RewriteRule .* - [CO=BALANCEID:balancer.www2:.www.mydomain.com]
<Directory "/u01/mydomain.com/wwwroot/www/">
AllowOverRide All
</Directory>
</VirtualHost>

Avatar
dalesaurus

Community Member, 283 Posts

23 May 2010 at 5:54am

I'm no expert but maybe add the following to your proxy:

ProxyHTMLURLMap http://www.example.com /

However I'm not sure how to make it force redirect to www like mod_rewrite. This might be a better question for http://serverfault.com/

Avatar
levinng

Community Member, 2 Posts

23 May 2010 at 5:59am

Finally solved this problem by adding "ProxyPreserveHost On" in Load Balancer config. Thank you for your reply!!