Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The title pretty much says it all. Basically, I want to route a request to a specific backend server based on the request's source IP.


HTTP Request from -> HAProxy -> BackendServer A
HTTP Request from -> HAProxy -> BackendServer B
share|improve this question
Hashed, or explicit mapping? – womble Jul 28 '11 at 13:39
Sorry, I'm not that versed with proxies and networking in general, so I'm not sure what you mean by hashed. Would either of those two, hashed or explicit, give me the desired result? – John Jul 28 '11 at 13:43
I don't know, it depends on whether your desired result is for hashed or explicit mapping. – womble Jul 28 '11 at 14:02
Explicit mapping means what you wrote literally: there's a file somewhere listing each IP. Hashed means there's a deterministic mapping from source IP address to backend, so the same IP address is always directed to the same backend. (until the number of available backends changes.) – Szocske Jul 28 '11 at 14:34
Thanks Szocske for explaining the difference to me. Appreciate it! – John Jul 28 '11 at 19:57
up vote 5 down vote accepted

I would do this by creating separate backends, then then route them accordingly from the front end based on the source IP:

For instance:

frontend foo
   acl is_A src
   acl is_B src
   use_backend A if is_A
   use_backend B if is_B
backend A
   server blah
backend B
   server baz

You could also put a list of ips in a file and then source the file with something like acl is_A src -f /etc/haproxy/special_ips

share|improve this answer
Thanks Kyle! I actually RTFM and figured it out, but I appreciate your answer because it validates that I got it right. Thanks again! :) – John Jul 28 '11 at 19:12

Your Answer


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.