Apache Balancing by source IP

apache-2.2load balancingPROXY

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?

Best Answer

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.

Related Topic