Forum Discussion

Singh_74932's avatar
Singh_74932
Icon for Nimbostratus rankNimbostratus
Oct 08, 2008

conditional select

Ok here is what i want to do and i tried witting some thing my self this time :

 

 

Logically :

 

 

if host name = xyz.com

 

 

then select pool member a from

 

 

else if host name = abc.com

 

 

select pool member b from same pool

 

 

 

Syntax :

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] equals "xyz.com" } {

 

LB::reselect pool myPool member1

 

} else if {[HTTP::host] equals "xyz.com" }

 

LB::reselect pool myPool member2

 

}

 

 

Let me know

 

 

10 Replies

  • You can just use the pool command with the member. You don't need to use LB::reselect in this case. The pool wiki page has some examples (Click here).

     
     when HTTP_REQUEST { 
        if {[string tolower [HTTP::host]] equals "xyz.com" } { 
      
           pool myPool member 10.1.2.100 80 
      
        } elseif {[string tolower [HTTP::host]] equals "abc.com" } 
      
           pool myPool member 10.1.2.200 80 
        } else { 
            take some default action? 
        } 
     } 
     

    You might also want to check if the pool member is up before using it. You can do this with LB::status pool member (Click here)

    Aaron
  • Or, you might want to consolidate those two "string tolower"'s into one with a switch to avoid unnecessary memory allocations.

    when HTTP_REQUEST { 
       switch [string tolower [HTTP::host]] { 
         "xyz.com" { 
           pool myPool member 10.1.2.100 80 
         } 
         "abc.com" { 
           pool myPool member 10.1.2.200 80 
         } 
         default { 
            take some other action. 
         } 
       } 
     }

    -Joe
  • Guys .. qq sa this virtual server is already having one irule i just got confused over what sequence traffic will hit iruule.. i mean this is what UI shows me :

     

     

    irule1 - triger on even http_request

     

    irule2 - triger on even http_request

     

    irule3 - triger on even http_response

     

     

    Also let me add that change too to save mem .. thanks allot
  • Hi Rajwinder,

     

     

    Check this post for info and links on multiple iRules configured on the same VIP (Click here).

     

     

    Aaron
  • cool ..

     

     

    I have another virtual server handling httpS. and unfortunelty no http profile attached to it. Only TCP profile is attached.

     

     

    so can i modify the above rule as :

     

     

    when SERVER_CONNECTED {

     

     

    or

     

     

    when CLIENT_ACCEPTED {

     

     

    rest same ?

     

     

     

     

  • If you're not decrypting the SSL, you won't be able to inspect the HTTP headers or data. If you need to pass the request via SSL to the pool, you could decrypt the traffic using a client SSL profile, parse the data as HTTP with an HTTP profile and then re-encrypt it on the server side using a server SSL profile.

     

     

    Aaron
  • ah .. so that means if i have to put any rule on VS handling https i have to put certificates + private key on big ip itself to decrypt and then encrypt it again ? I
  • You don't have to re-encrypt the server side connection unless your security requirements dictate that, or the server(s) only accept HTTPS traffic.

     

     

    Aaron
  • Need some views here :

     

     

    I have applied the rule on a virtual server where :

     

     

    1. No default pool is there

     

    2. No persistance profile is set of any kind

     

    3. Round robin is used for load balancing.

     

     

     

    I doubt that once the session is established big ip wouldnt apply the irule to the packet that follow. Cause i verified that bigip did get the hostname correct but didnt redirect the packets to the member i want to

     

     

    Please suggest.

     

     

    Thanks

     

    Rajwinder
  • This is probably due to clients making multiple requests over the same TCP connection. If so, you can enable OneConnect to fix the issue:

     

     

    OneConnect? For my iRule?

     

    http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=114

     

     

    Aaron