Forum Discussion
Tokyo_Jihen_931
Dec 03, 2010Nimbostratus
iRule for URL persistence
Hello all,
I am a newbie of iRules programming. My system is BIG-IP 9.1.2. I am trying to implement persistence using a string that appear in URL.
For example.
http://test.big-ip.com/install/123456
http://test.big-ip.com/scripts/456788
I want the system when seeing the identifier (e.g. 123456, 456788) in the URL, it will use that identifier to persist my traffic to my nodes.
The identifier is always contains 6 characters and should be after the string "install/" or "scripts/"
Does anyone have similar environment with me? Or can provide me any iRule sample to do this?
Thanks
- Chris_MillerAltostratusBasically, if the URI contains "123456," go to server 1 and if it contains "456788," goes to server 2?
- hooleylistCirrostratusMaybe something like this?
when HTTP_REQUEST { Check for /install/ or /scripts/ in the path switch -glob [HTTP::path] { "*/install/*" { Parse the URI "directory" after install. Look for /install/, skip 9 characters and match up to the next /. set session_id [findstr [HTTP::path] /install/ 9 /] } "*/scripts/*" { Parse the URI "directory" after scripts. Look for /scripts/, skip 9 characters and match up to the next /. set session_id [findstr [HTTP::path] /scripts/ 9 /] } default { set session_id "" } } if {$session_id ne ""}{ Persist on the parsed session ID for X seconds persist uie $session_id 1800 } }
- hooleylistCirrostratusActually, this might not work. With the above approach, the client could get load balanced to a different server than the one that generated the session. To avoid this scenario, you'd need to parse the persistence token in the response and then persist on it in subsequent requests.
- Tokyo_Jihen_931NimbostratusThank you very much Aaron.
- Chris_MillerAltostratusYou don't necessarily need to set it as a sessionid, you should simply be able to send the request to server x.
when HTTP_REQUEST { switch -glob [HTTP::uri] { "*123456*" { pool poolname member x.x.x.x y } "*456788*" { pool poolname member x.x.x.x y } }}
- Colin_Walker_12Historic F5 AccountThat should work fine, Chris. There's no need for persistence technically, if you're going to use the iRule for redirection every time anyway. You could of course set persistence within the switch, but that's only if you want to be able to get the user back to the same server without the use of the iRule.
- Tokyo_Jihen_931NimbostratusThank you very much Chris~~
- hooleylistCirrostratusI think you'd need to parse the random token from the response and create a persistence record then. Else, just by just looking at the request, the client would be load balanced again and then on that response LTM would add a persistence record. If the random token is only found in the response headers you could use HTTP::header $header_name to parse it and then add a persistence record with the persist add command. Else, if the token is in the response payload, you could use a stream profile and iRule like this:
- Chris_MillerAltostratusSo, it's not the "123456" that determines which server to go to, but the "xxxxxxx" part?
- yxshybj_101037NimbostratusI have a environment , can't use insert client ip in the http head , but the device(is not the end client ) in front of f5 coult insert the client ip in the url in the follow format ,:
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