Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Rewrite rule for apache load balancer

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

Page: 1
Go to End
Author Topic: 3316 Views
  • levinng
    Avatar
    Community Member
    2 Posts

    Rewrite rule for apache load balancer Link to this post

    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>

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Rewrite rule for apache load balancer Link to this post

    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/

  • levinng
    Avatar
    Community Member
    2 Posts

    Re: Rewrite rule for apache load balancer Link to this post

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

    3316 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.