5

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.

i.e.,

HTTP Request from 192.168.100.1 -> HAProxy -> BackendServer A
HTTP Request from 192.168.100.2 -> HAProxy -> BackendServer B
John
  • 536
  • 3
  • 5
  • 13
  • 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
  • 2
    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

1 Answers1

9

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 192.168.100.1
   acl is_B src 192.168.100.1
   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

Kyle Brandt
  • 83,619
  • 74
  • 305
  • 448
  • 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