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.

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
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
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
add comment

1 Answer

up vote 4 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 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

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
add comment

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.