Forum Discussion
rjordan
Nimbostratus
Jul 30, 2010Setting the domain of a cookie
Up until now, we were able to handle all of our persistence needs with the default cookie persistence. Now we have an application running on www.foo.com and sub.foo.com. We need to maintain persistence across the subdomains (which point to the same VS).
When I access www.foo.com, the domain of the cookie is set to "foo.com", which is not valid for sub.foo.com. Setting the cookie domain to "(dot).foo.com" should fix my persistence issues, but I'm not quite sure how to accomplish this.
Would I create an iRule using the necessary HTTP::cookie settings, then associate it with a new cookie persistence profile? Can someone point me in the right direction with a basic example? I checked the code share and didn't find much that would help. I feel that if I could replicate the default cookie persistence with an iRule, then I could easily tweak the domain setting.
Thanks.
5 Replies
- hoolio
Cirrostratus
Hi,
You can use an iRule like the one linked below to set the domain on the persistence cookie. You can use this in conjunction with a cookie persistence profile. That would be the simplest combination compared with setting cookie persistence in an iRule (as you have to have a cookie persistence profile enabled on the VS to use the persist cookie iRule commands anyhow).
http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/afv/topic/aft/14143/aff/5/showtab/groupforums/Default.aspx14151
Aaron - rjordan
Nimbostratus
That did the trick!
On a related note, I'm a little worried about hard coding the cookie domain as it would cause issues if the VS was accessed using another domain name. Should I be able to trim HTTP::host and set that as the cookie domain (preceded by the dot)? The default cookie persistence does this, but I don't know how. Any recommendations on which string method would work best for this? - hoolio
Cirrostratus
You could use the domain command to do this:
http://devcentral.f5.com/wiki/default.aspx/iRules/domain
[domain www.sub.my.domain.com 2] -> domain.com
You might want to check that the host header isn't an empty or an IP address first. Here is an untested example:when HTTP_REQUEST { if { [string match {*[a-zA-Z]*} [HTTP::host]]}{ set domain [domain [HTTP::host] 2] } else { set domain "" } } when HTTP_RESPONSE { Check if the persistence cookie exists in the response if {[HTTP::cookie exists "BIGipServer[LB::server pool]"] and $domain ne ""} { set the domain attribute on the persistence cookie HTTP::cookie domain "BIGipServer[LB::server pool]" $domain } }
Aaron - rjordan
Nimbostratus
That's exactly what I was looking for! My last question: I currently have an iRule that directs the request to a particular node based on a value in the uri string. Is it recommended to integrate the cookie persistence into the existing iRule or should I apply multiple iRules to the VS? - hoolio
Cirrostratus
The two rules shouldn't conflict with each other and serve different purposes, so I'd leave them as separate iRules applied to the same VS.
Aaron
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
