Forum Discussion

htuytela_37346's avatar
htuytela_37346
Icon for Nimbostratus rankNimbostratus
Dec 20, 2013

host header load-balancing

Hi,

I'm having a question on host-header load balancing, or something similar. To be more specific, I have a conditional irule where the pools listen to different URL's.

This is what I have at this moment :

when HTTP_REQUEST {
  switch -glob [HTTP::header value "User-Agent"] {
    "*MSIE 6*" -
    "*MSIE 7*" -
    "*MSIE 8*" {
       pool site-10.130.14.98_9610
    }
    default {
      pool site-10.130.14.98_29710
    }
  }
}

The problem is that this pool site-10.130.14.98_9610 is actually only giving correct output on msie.foo.com/login/ and site-10.130.14.98_29710 listens to listening www.foo.com Basically, if I could add the /login to site-10.130.14.98_9610, that would do the trick as well, as only the /login is important. The default pool works fine.

Thank you,

Hans

10 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account

    So what it sounds like you need is to balance based on URI first, and then User-Agent after that. I.E. if the user is accessing msie.foo.com/login, then decide where to route things based on their User-Agent. Otherwise, send everything to the default pool, since it is the one that is set up to handle all of foo.com. Does that sound correct?

    If so, you're awfully close, and just need to add another conditional. Try this:

    
    when HTTP_REQUEST { 
      switch -glob [HTTP::header value "User-Agent"] { 
        "_MSIE 6_" - 
        "_MSIE 7" - 
        "_MSIE 8" { 
          if {[HTTP::uri] eq "/login"} { 
            pool site-10.130.14.98_9610 
          } else { 
            pool site-10.130.14.98_29710 
          } 
        } 
        default { 
          pool site-10.130.14.98_29710 
        } 
      }
    }
    

    • htuytela_37346's avatar
      htuytela_37346
      Icon for Nimbostratus rankNimbostratus
      Hi Colin, thank you for your reply. Basically, let me clarify some more. My problem is that I have 2 backend web servers that listen on different FQDN's, and that I need to redirect based on browser-type. So the URL, pointing to the F5, is www.foo.com. When IE used, the user is redirected to pool site-10.130.14.98_9610, but that server needs to suffix /login to give a valid response, so he is only listening to www.foo.com/login. The default server is listening www.foo.com. At this moment, the redirect based on IE works, but since the wrong FQDN is used, the users does not get the correct page displayed. So somehow, I need to make a conditional URL rewrite. Thanks, Hans
  • So you just need to rewrite the URI?

    when HTTP_REQUEST {
        switch -glob [HTTP::header value "User-Agent"] {
            "*MSIE 6*" -
            "*MSIE 7*" -
            "*MSIE 8*" {
                pool site-10.130.14.98_9610
                HTTP::uri "/login"
            }
            default {
                pool site-10.130.14.98_29710
            }
        }
    }
    
  • Thank you for your reply. There seems to be a loop in the iRule. It now looks like traffic is being redirected to the virtual server again, with the suffix /login added, which obviously causes this loop when the user uses MSIE. I just would need the /login suffix added, and the pool site-10.130.14.98_9610 to be used. This is my current iRule :

    when HTTP_REQUEST {
      switch -glob [HTTP::header value "User-Agent"] {
        "*MSIE 6*" -
        "*MSIE 7*" -
        "*MSIE 8*" {
        log local0. "[IP::client_addr]:[TCP::client_port]: Matched MSIE."
        pool site-10.130.14.98_9610
        HTTP::uri "/login"   
        }
        default {
        log local0. "[IP::client_addr]:[TCP::client_port]: Matched default pool" 
          pool site-10.130.14.98_29710
        }
      }
    }
    
  • Can you try this :

    when HTTP_REQUEST {
      switch -glob [HTTP::header value "User-Agent"] {
        "*MSIE 6*" -
        "*MSIE 7*" -
        "*MSIE 8*" {
        log local0. "[IP::client_addr]:[TCP::client_port]: Matched MSIE."
        pool site-10.130.14.98_9610
            if { ![string tolower [HTTP::uri]] equals "/login" }{
                HTTP::uri "/login"   
            }
        }
        default {
        log local0. "[IP::client_addr]:[TCP::client_port]: Matched default pool" 
          pool site-10.130.14.98_29710
        }
      }
    }
    

    I added a condition for your URI rewriting action.

  • Hi Thomas, unfortunately, that did not work neither. Basically, I'm looking to add the /login suffix for requests made by MSIE users, who then need to be directed to a seperate pool of servers. The actual user is not to type the /login suffix himself. I believe your if statement expects the /login typed in the browser, doesn't it ? So a conditional rewrite of the URL....

     

  • Ok, so you want your user to be redirected to /login page if he uses MSIE 8 ?

    Did you try to redirect your user with

    HTTP::redirect "http://[HTTP::host]/login"
    
  • Thanks, this somewhat does the redirect, although I would not like the URL in the browser to change. I'd like to keep it the same for both browsers. how do I do that?

     

  • Or you can do this like that :

    when HTTP_REQUEST {
      switch -glob [HTTP::header value "User-Agent"] {
        "*MSIE 6*" -
        "*MSIE 7*" -
        "*MSIE 8*" {
            set URI_Origin "[HTTP::uri]"        
            log local0. "[IP::client_addr]:[TCP::client_port]: Matched MSIE."
            pool site-10.130.14.98_9610
                if { ![string tolower [HTTP::uri]] equals "/login" }{
                    HTTP::uri "/login/$URI_Origin"   
                }
            }
        default {
        log local0. "[IP::client_addr]:[TCP::client_port]: Matched default pool" 
          pool site-10.130.14.98_29710
        }
      }
    }
    

    You can also take a look at Cookie insertion.