Forum Discussion

Vova_1985_18320's avatar
Vova_1985_18320
Icon for Nimbostratus rankNimbostratus
May 19, 2015

Cookie persistence + iRule

Hi,

 

I have VS configured with iRule and persistence profile:

 

iRule: when HTTP_REQUEST { bla bla bla bla bla bla } else { pool DNN_HTTP persist cookie insert lbhint 0

 

Persistence profile: Cookie Method: Insert Name: lbhint Always Send Cookie: Yes Expiration: Session Cookie

 

Now, my site configured to insert cookie named lbhint and the code checks if i dont have lbhint cookie it inserts it, then it checks each request if the cookie value equals to the servers that responded to my request, if it equals it does nothing, if its different it changes it to the server the responded.

 

Example: Request http://www.mysite.com (server-1 responded) --> code checks lbhint exists (no) --> insert lbhint=server-1 Request 2: (server-1 responded) --> code checks lbhint exist (yes) --> does it equal to server-1 (yes)? --> do nothing Request 3: (server-2 responded) --> code checks lbhint exist (yes) --> does it equals to server-2 (no) --> change value lbhint=server-2

 

Now, i want my LB to keep the session persistence based on this cookie but it doesn't work, i tired to play with the profile methods, but no luck. When i check http headers i noticed that i see 2 cookies named lbhint, one with server value and the other is random chars and numbers (somthing like 34jbvh5vetv345vhj35). Another thing i noticed that it failed most of the time when my request from http switched to https (its 2 VS, one for http and another for https, and so i have to iRules, one for http pools and one for https pools).

 

1) As you noticed server name inserted in lbhint is server-1 however my NODE name in F5 is server_1 (with underline) - Can it affect it? 2) Any ideas ti help me?

 

3 Replies

  • OK i actually want to make it easier: Ignore what my server does, lets focus only how to do it on F5 with standard cookie name. So i have 2 VS one for http and the other is https, they both configured to select pool by iRule, i need to configure cookie persistence across these 2 VSs. How can i do it right?

     

  • Hi Vova,

     

    Your message is quite confusing, it is difficult to understand what you are trying to achieve and what your requirements and problems are.

     

    I can see at least one problem here - you are trying to persist using both Profiles and iRules (hence the problem of you getting two Set-Cookie headers in the response headers - one comes from Persistence profile and another one from your iRule).

     

    If your requirement is just to persist across virtual servers you can use "Match Across Virtual Servers" checkbox in your persistence profile, BUT it has to be a Source-IP persistence, NOT Cookie persistence (no such option for Cookie Persistence)

     

    If you need to use Cookie persistence, I recommend that you read these two DevCentral posts:

     

    https://devcentral.f5.com/articles/persisting-across-virtual-servers

     

    https://devcentral.f5.com/codeshare?sid=574

     

    Hope this helps,

     

    Sam

     

  • My server provides to any request cookie named lbhint with value=servername, and i want to configure persistence based on this cookie on LB across 2 VS (same IP, one on port 80 and one on port 443 leading to the same servers). And its not working.

    Config: http VS 1.1.1.1:80 --> HTTP_POOL:server1:80/server2:80 https VS 1.1.1.1:443 --> HTTPS_POOL:server1:443/server2:443

    Example of what i need: First request: http://www.mysite.com it goes to http VS (lets assume LB redirected it to server1), now if i press "login button" it redirects me to: https://www.mysite.com so the request goes to https VS and at this stage i loose my persistent, instead of working with the sserver1 it goes to the server2.

    And besides this i have irule (the last HTTPS_POOL is the pool im talking about): And i have 2 irules like this, one for HTTP and the other for HTTPS.

    when HTTP_REQUEST {
       log local0.alert got request for [HTTP::uri];
       if {[string tolower [HTTP::uri]] starts_with /LpSys/} {
          Some_POOL
          persist none
          log local0.alert sending to LpSys pool
      } else {
          if {[string tolower [HTTP::uri]] starts_with /info/} {
              pool Some_POOL2
              persist cookie insert lbhint 0
              log local0.alert sending to info pool
    
          } else {
              if {[string tolower [HTTP::uri]] starts_with /mobile/} {
              pool SOME_POOL_3
              log local0.alert "sending to mobile pool
    
             } else {
              pool HTTPS_POOL
              persist cookie insert lbhint 0
           }
    
        }
    }
    }