Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using Apache's Proxy Balancer to balance one sub domain (e.g. subdomain.domain.com) to an application which is located on 2 servers. Here an extract from my Apache configuration file:

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

<Proxy balancer://cluster1>
    BalancerMember http://server1:28081 route=w1
    BalancerMember http://server2:28082 route=w2
</Proxy>

ProxyPass /path balancer://cluster1/path
ProxyPassReverse /path balancer://cluster1/path

My question is, if it's possible to decide with the source IP-address which BalancerMember should be used for the request? To e.g. Requests from 1.2.3.4 to Member 1?

share|improve this question
1  
I think you'll get better options and performance with Squid cache & accelerator –  anttiR Nov 11 '11 at 15:28
1  
IF your problem is you need the same client always to same server you could redirect every client to either /dir1 or /dir2 and then proxy them to backend servers accordingly. –  anttiR Nov 11 '11 at 15:31
    
Thanks. Will take a look on Squid. I have never used it before and I thought the proxy module is a good choice. :) The thing is also, that the data which I deliver changes really often so I don't know really if a cache makes sense here. –  High6 Nov 11 '11 at 16:39

2 Answers 2

up vote 3 down vote accepted

No. The Proxy Balancer Module will pass requests to a members based only on two factors:

  1. If the request has a sticky cookie specifying a member, then the request will be forwarded to that member (if it is available). Looks like you do not have this configured however.
  2. Otherwise the request will be forwarded according to the distribution algorithm. There are three configurable algorithsm, they are Simple Round Robin, Least Traffic (bytes), and Least Requests (all have weighting available).

You can enable sticky sessions by cookie. How you want to do this may depend on your back end unless you want Apache to add another cookie regardless of what the back end is doing.

Side notes: HAProxy, Squid, and Nginx are all pretty good at load balancing and caching. Apache's proxy module is usually good enough for light and medium loads though, and it sounds like you're already familiar with it. Apache's disadvantage is that it's like a Swiss Knife: does everything reasonably well, doesn't do anything exceptionally well, and it's a bit bulky. Using an address redundancy system like CARP will allow a Linux or BSD box to become a Highly Available Proxy Balancer too.

share|improve this answer
    
Oh, OK. Thanks a lot for the detailed answer. I will take a look on this cookie approach. –  High6 Nov 11 '11 at 16:23

You can try the following configuration:

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

<Proxy balancer://cluster1>
    BalancerMember http://server1:28081 route=w1
</Proxy>

<Proxy balancer://cluster2>
    BalancerMember http://server2:28082 route=w2
</Proxy>

RewriteEngine On
# redirect clients from 1.2.3.4 to the first member
RewriteCond %{REMOTE_ADDR}  !^1\.2\.3\.4$
RewriteRule ^/path(.*)$ balancer://cluster1/path$1  [P,L]


#  This rule will take care of the rest clients
ProxyPass /path balancer://cluster2/path
ProxyPassReverse /path balancer://cluster2/path
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.