Forum Discussion

Jim_Jack_103645's avatar
Jim_Jack_103645
Icon for Nimbostratus rankNimbostratus
Aug 27, 2007

redirect based on uri

We have a pool of servers which we direct our traffic to. Our testers want to be able to choose which server their request goes to by using a querystring.

 

e.g. we have servers a, b, c, d and e in the pool.

 

If they use querystring 'lbsc=d' in the uri then we direct traffic to server 'd'

 

Does anyone have any ideas?

 

6 Replies

  • Here is my first attempt.

     

    It first attempt to see if the request if from a bot and sends to a specialised server if it is

     

    It then looks for the querystring and sends accordingly.

     

    Finaly, if the querystring is not found, it sends to a default pool.

     

    Can I have a peer review?

     

     

    when HTTP_REQUEST {

     

    if { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } {

     

    is a bot .. send to the bot server

     

    pool MIS-BOT50-DM

     

    } else {

     

    regular traffic

     

    set v1 [URI::query [HTTP::uri] "lbsc"]

     

    switch { v1 } {

     

    "c" {

     

    pool MIS-WEB50C

     

    }

     

    "d" {

     

    pool MIS-WEB50D

     

    }

     

    "e" {

     

    pool MIS-WEB50E

     

    }

     

    "f" {

     

    pool MIS-WEB50F

     

    }

     

    default {

     

    pool MIS-WEB50-DM

     

    }

     

    }

     

    }

     

    }
  • That looks like a good start. I think your switch statement is slightly off though. Are you ever seeing traffic go to any but the default pool?

    I think {v1} would be evalutated as a literal string of v1, not the variable value for $v1. Regardless, you can avoid using the variable altogether.

    
    switch [URI::query [HTTP::uri] "lbsc"] {
       "" {
          pool MIS-WEB50-DM
       }
       "c" {
          pool MIS-WEB50C
       }
       "d" {
          pool MIS-WEB50D
       }
       "e" {
          pool MIS-WEB50E
       }
       "f" {
          pool MIS-WEB50F
       }
       default {
          pool MIS-WEB50-DM
       }
    }

    If most of your requests won't have the lbsc parameter set, you could have the first test in the switch be "".

    Aaron
  • This works, but only for the first request. Subsequent requests are directed to other servers in the pool, I asume by persistence. Is there any way to switch it off and persist to the requested node??

     

     

    when HTTP_REQUEST {

     

    if { ([matchclass [string tolower [HTTP::header User-Agent]] contains $::bots])

     

    or

     

    ([ matchclass [ IP::client_addr ] equals $::bot_ips ]) } {

     

    is a bot .. send to the bot server

     

    pool MIS-BOT20-01

     

    } else {

     

    regular traffic

     

    switch [URI::query [HTTP::uri] "lbsc"] {

     

    "" {

     

    pool MIS-WEB20-1

     

    }

     

    "c" {

     

    node 10.60.1.234

     

    }

     

    "d" {

     

    node 10.60.1.104

     

    }

     

    "e" {

     

    node 10.60.2.124

     

    }

     

    "f" {

     

    node 10.60.2.6

     

    }

     

    "g" {

     

    node 10.60.2.55

     

    }

     

    "botc" {

     

    node 10.60.1.134

     

    }

     

    "botd" {

     

    node 10.60.2.34

     

    }

     

    default {

     

    pool MIS-WEB20-1

     

    }

     

    }

     

    }

     

    }
  • I tried to add cookie persistence to the irule to no effect:

     

     

    when HTTP_REQUEST {

     

    if { ([matchclass [string tolower [HTTP::header User-Agent]] contains $::bots])

     

    or

     

    ([ matchclass [ IP::client_addr ] equals $::bot_ips ]) } {

     

    is a bot .. send to the bot server

     

    pool MIS-BOT20-01

     

    } else {

     

    regular traffic

     

    switch [URI::query [HTTP::uri] "lbsc"] {

     

    "" {

     

    pool MIS-WEB20-1

     

    }

     

    "c" {

     

    persist cookie

     

    node 10.60.1.234

     

    }

     

    "d" {

     

    persist cookie

     

    node 10.60.2.104

     

    }

     

    "e" {

     

    persist cookie

     

    node 10.60.2.124

     

    }

     

    "f" {

     

    persist cookie

     

    node 10.60.2.6

     

    }

     

    "g" {

     

    persist cookie

     

    node 10.60.2.55

     

    }

     

    "botc" {

     

    persist cookie

     

    node 10.60.1.134

     

    }

     

    "botd" {

     

    persist cookie

     

    node 10.60.2.34

     

    }

     

    default {

     

    pool MIS-WEB20-1

     

    }

     

    }

     

    }

     

    }
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    Apply a OneConnect profile to the virtual, and you should see that each request on the same connection is evaluated & routed to the desired pool. (Without OneConnect, the first pool chosen is used for the life of the connection.)

     

     

    HTH

     

    /deb