Forum Discussion
F5irulelearner_
Nimbostratus
Aug 01, 2014irule to read the url and store as cookie
Hello,
I am working to divert the traffic to a specific server based on the servername passed in the URL. Can you please help with an irule which reads the url and stores it as a cookie
Exa...
nitass
Employee
Aug 05, 2014i agree with Kevin. you should use persistence method. using query parameter value as cookie value will result all request goes to only one pool member (because parameter value is same).
e.g.
config
root@(B6900-R69-S40)(cfg-sync Standalone)(Active)(/Common)(tmos) list ltm virtual bar
ltm virtual bar {
destination 100.100.100.41:80
ip-protocol tcp
mask 255.255.255.255
persist {
cookie {
default yes
}
}
profiles {
http { }
tcp { }
}
rules {
qux
}
source 0.0.0.0/0
source-address-translation {
type automap
}
vs-index 2
}
root@(B6900-R69-S40)(cfg-sync Standalone)(Active)(/Common)(tmos) list ltm rule qux
ltm rule qux {
when HTTP_REQUEST {
set qry [URI::query [HTTP::uri] app]
if { $qry ne "" } {
switch $qry {
"qwa1234" { pool lpqwa1234-25046 }
"qwa5678" { pool lpqwa5678-25046 }
default { pool app-E2-openhome-25046 }
}
} else {
if { [HTTP::cookie exists BIGipServerapp-E2-openhome-25046] } {
pool app-E2-openhome-25046
} elseif { [HTTP::cookie exists BIGipServerlpqwa1234-25046] } {
pool lpqwa1234-25046
} elseif { [HTTP::cookie exists BIGipServerlpqwa5678-25046] } {
pool lpqwa5678-25046
} else {
pool app-E2-openhome-25046
}
}
}
when HTTP_RESPONSE {
log local0. "client [IP::client_addr]:[TCP::client_port] server [IP::server_addr]:[TCP::server_port] \
pool [LB::server pool]"
}
}
test
[root@client3 ~] curl -I http://100.100.100.41
HTTP/1.1 200 OK
Date: Tue, 05 Aug 2014 10:41:58 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Sun, 09 Feb 2014 08:39:51 GMT
ETag: "41879c-59-2a9c23c0"
Accept-Ranges: bytes
Content-Length: 89
Content-Type: text/html; charset=UTF-8
Set-Cookie: BIGipServerapp-E2-openhome-25046=1707657416.20480.0000; path=/
[root@client3 ~] curl -I http://100.100.100.41/?app=qwa1234
HTTP/1.1 200 OK
Date: Tue, 05 Aug 2014 10:42:05 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Sun, 09 Feb 2014 08:39:51 GMT
ETag: "41879c-59-2a9c23c0"
Accept-Ranges: bytes
Content-Length: 89
Content-Type: text/html; charset=UTF-8
Set-Cookie: BIGipServerlpqwa1234-25046=1707657416.20480.0000; path=/
[root@client3 ~] curl -I http://100.100.100.41/?app=qwa5678
HTTP/1.1 200 OK
Date: Tue, 05 Aug 2014 10:39:22 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Tue, 08 Nov 2011 12:26:29 GMT
ETag: "4183f1-30-47e02740"
Accept-Ranges: bytes
Content-Length: 48
Set-Cookie: AUTHTOKEN=5678; path=/
Content-Type: text/html; charset=UTF-8
Set-Cookie: BIGipServerlpqwa5678-25046=1724434632.20480.0000; path=/
[root@client3 ~] curl -I http://100.100.100.41 -H "Cookie: BIGipServerlpqwa5678-25046=1724434632.20480.0000"
HTTP/1.1 200 OK
Date: Tue, 05 Aug 2014 10:39:39 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Tue, 08 Nov 2011 12:26:29 GMT
ETag: "4183f1-30-47e02740"
Accept-Ranges: bytes
Content-Length: 48
Set-Cookie: AUTHTOKEN=5678; path=/
Content-Type: text/html; charset=UTF-8
/var/log/ltm
[root@B6900-R69-S40:Active:Standalone] config tail -f /var/log/ltm
Aug 5 03:54:15 B6900-R69-S40 info tmm3[15766]: Rule /Common/qux : client 100.100.100.3:32919 server 200.200.200.101:80 pool /Common/app-E2-openhome-25046
Aug 5 03:54:22 B6900-R69-S40 info tmm1[15765]: Rule /Common/qux : client 100.100.100.3:32920 server 200.200.200.101:80 pool /Common/lpqwa1234-25046
Aug 5 03:54:29 B6900-R69-S40 info tmm[15765]: Rule /Common/qux : client 100.100.100.3:32921 server 200.200.200.102:80 pool /Common/lpqwa5678-25046
Aug 5 03:54:46 B6900-R69-S40 info tmm3[15766]: Rule /Common/qux : client 100.100.100.3:32922 server 200.200.200.102:80 pool /Common/lpqwa5678-25046
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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