Forum Moderators: phranque

Message Too Old, No Replies

Apache Load Balancer "pass through URL"

         

dunnma

3:53 pm on Mar 2, 2010 (gmt 0)

10+ Year Member



So I have a basic setup. An LB using Apache as the Load Balancer and 2 backend servers for serving content.

The LB looks like:

<VirtualHost *:80>

DocumentRoot /var/www/
ProxyRequests off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

<Proxy balancer://mycluster>
# ws1
BalancerMember http://internal-ip-1:80
# ws2
BalancerMember http://internal-ip-2:80

ProxySet lbmethod=byrequests

</Proxy>

ProxyPass / balancer://mycluster/ stickysession=PHPSESSID|phpsessid nofailover=On

</VirtualHost>


When I was on one server everything worked fine with my rewrites. Now that I added the LB it doesn't worked. I turned on logging on the webserver and here is what I see:

RewriteCond: input='10.0.0.0' pattern='!^domain\.com$' [NC] => matched
rewrite '/' -> 'http://domain.com/'


So basically everything is technically working it is just that because the load balancer is passing through the input of its' internal IP instead of the URL it is an infinite redirect. What on the LB side of things do I need to change so it passes through the URL instead of the IP?

Or do I need to find a different solution to Apache?

jdMorgan

5:30 pm on Mar 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem may be that mod_proxy is getting invoked first, changing the requested hostname to the IP address of one of the back-end servers, and thus (re-)invoking your domain canonicalization redirect.

A possible fix is to exclude IP-address hostnames from your domain canonicalization redirect rule:

RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteCond %{HTTP_HOST} !^10\.
RewriteRule ^/ http://example.com/$1 [R=301,L]

Note that the [NC] flag was removed from the hostname pattern, and that the pattern now matches (excludes) blank hostnames as well, to avoid an infinite loop if you get a true HTTP/1.0 client request.

Jim

dunnma

6:13 pm on Mar 2, 2010 (gmt 0)

10+ Year Member



I made the change and it did stop the looping. However it still always passes in the "input" of the internal IP. I cannot check for subdomains or any other items.

In order to solve this the LB has to pass through the URL otherwise you can never reliably use Rewrite.