Forum Discussion
Dan_Hughes_1946
Nimbostratus
Jan 06, 2010loadbalanced redirection
Howdy,
Wondering if anyone can suggest a solution to a little problem I have. I want traffic coming into an LTM to be redirected to one of two URLs - based on a round robin loadbanace. So :
client sends request to www.domain.com
LTM returns HTTP redirect to either firsthost.domain.com or secondhost.domain.com based on a round robin loadbalance..
I can see lots of ways of returning a single redirect in a given set of circumstances, and I see of course simple ways to proxy/forward to a pool of servers. But I can't see an obvious method of load balancing to multiple redirects.
Any help appreciated!
Dan
- Colin_Walker_12Historic F5 AccountIf you just want even distribution of load to two redirects then you'd just need to do something like:
when CLIENT_ACCEPTED { set count 0 } when HTTP_REQUEST { switch $count { 0 { HTTP::redirect "firsthost.domain.com" set count 1 } 1 { HTTP::redirect "secondhost.domain.com" set count 0 } } }
- The_Bhattman
Nimbostratus
Hi Dan,when HTTP_REQUEST { set turnbit [expr [STATS::get "roundrobin" turnbit] %2] switch $turnbit { 0 { log local0. "$turnbit" HTTP::redirect "http://firsthost.domain.com" STATS::incr "roundrobin" turnbit } 1 { log local0. "$turnbit" HTTP::redirect "http://secondhost.domain.com" STATS::incr "roundrobin" turnbit } } }
- hoolio
Cirrostratus
I think it would actually be more evenly distributed with a global counter or a session table entry. - Dan_Hughes_1946
Nimbostratus
Guys, - Dan_Hughes_1946
Nimbostratus
Hi Hoolio, - Dan_Hughes_1946
Nimbostratus
OK one more question on this. Lets say I wanted to have a health monitor on the rewrite destinations. Is it possible to make the use of each redirect URL dependent on the state of a monitored node? - hoolio
Cirrostratus
I think in this particular situation we shouldn't get too much of a problem, as the connection coming into the LTM is an initial connect from a URL in the application. Once it gets redirected, the real action happens, so a user (probably) only sends one connection to the load balancer.
Example of round robin redirection when RULE_INIT { Initialize the redirect counter to 0 set ::redirect_counter 0 } when HTTP_REQUEST { Check the counter value switch $::redirect_counter { 0 { Value was 0, redirect to first URL with cache control headers set to prevent caching of response HTTP::respond 302 Location "http://firsthost.domain.com" Cache-Control No-Cache Pragma No-Cache set ::redirect_counter 1 } 1 { Value was 1, redirect to second URL with cache control headers set to prevent caching of response HTTP::respond 302 Location "http://secondhost.domain.com" Cache-Control No-Cache Pragma No-Cache set ::redirect_counter 0 } } }
when HTTP_REQUEST { For a load balancing selection from the VIPs default pool This assumes you've set the pool's load balancing algorithm to round robin switch [LB::select] { "1.1.1.1" { Send client a 302 redirect with the hostname which corresponds to the 1.1.1.1 server IP HTTP::respond 302 Location "http://firsthost.domain.com" Cache-Control No-Cache Pragma No-Cache } "2.2.2.2" { Send client a 302 redirect with the hostname which corresponds to the 2.2.2.2 server IP HTTP::respond 302 Location "http://secondhost.domain.com" Cache-Control No-Cache Pragma No-Cache } default { Take some default action if both servers are marked down? } } }
- Dan_Hughes_1946
Nimbostratus
Hi Aaron, - Dan_Hughes_1946
Nimbostratus
Great. Thanks all of you! Glad to be following the logic too! - htran
Nimbostratus
Sorry to jump in the middle. Can I have a quick question:
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects