Forum Discussion
irule to select pool based on url
Hi All,
I am new to f5 irules.
I need an irule that can select which pools to go base on the url.
Example :
url1 : https://www.abc.com
url2 : https://www.abc.com/dashboard
Both of the url will resolve into 10.10.10.10
When the user hit url1 : https://www.abc.com , it will go to pool_A.
When the user hit url1 : https://www.abc.com/dashboard , it will go to pool_B.
Thanks.
9 Replies
- Kevin_Stewart
Employee
Here's a quick iRule example:
when HTTP_REQUEST { switch -gob [string tolower [HTTP::uri]] { "/dashboard*" { pool pool_B } "/" { pool pool_A } default { pool pool_A } } }
But then you can also do this task with an LTM policy and no iRules at all. Remember to enable OneConnect in the virtual server and in the associated HTTP profile to be able to do this context-based load balancing.
- Lee_Payne_53457
Cirrostratus
Something like this: when HTTP_REQUEST { switch [string tolower [HTTP::uri]] { "/" { pool pool_A } "/dashboard" { pool pool_B } default { } } }
You can then add others as required, if you want do do partial matches using regex
- Kevin_Stewart
Employee
If I may add,
If you do wildcard matching - the switch -glob option (which is actually not regex), you should put the more specific URIs first. If you put "/*" first, then all requests will match this.
You don't have to specify a default action, but it's recommended.
- janlaw_195243
Nimbostratus
Hi All, Thanks for the help, i will try this irules asap. The members in both of the pools are the same, just that the ports are different. pool_A is for 443 and pool_B is for 8000. Should i enable the port translation at the virtual sever, so that it will translate from 443 to 8000 if it hit pool_B? Thanks. - janlaw_195243
Nimbostratus
Hi All, Thanks for the help, i will try this irules asap.
The members in both of the pools are the same, just that the ports are different. pool_A is for 443 and pool_B is for 8000.
Should i enable the port translation at the virtual sever, so that it will translate from 443 to 8000 if it hit pool_B?
Thanks.
- Kevin_Stewart
Employee
Should i enable the port translation at the virtual sever, so that it will translate from 443 to 8000 if it hit pool_B?
You absolutely must enable port translation in the VIP if you want this to work. Is it also that one pool is doing SSL and the other is not?
- Kevin_Stewart
Employee
is there any problem that i will face??
Not if both are doing SSL. I was thinking that maybe one was doing SSL (the 443 pool) and one was not (the 8000 pool), in which case you'd have to also enable or disable the server SSL profile in the VIP according to the pool selection.
- Kevin_Stewart
Employee
If you're controlling ALL pool access form the iRule, then no you don't have to add the pool to the VIP.
- Kevin_Stewart
Employee
May i know what is OneConnect for and why is a must to enable it?
When you load balance to a server in a pool, the BIG-IP establishes direct TCP connections with that pool member (as a proxy would). If you're doing "content switching", where you're sending traffic to different pools based on some request criteria, you may run into a situation where the BIG-IP has an established TCP connection with one pool member and won't immediately sever that connection and start a new one somewhere else. The OneConnect profile (applied in the virtual server and in the associated HTTP profile) allows you to safely switch between pool members.
Please see the following solution article for more details:
https://support.f5.com/kb/en-us/solutions/public/7000/200/sol7208.html?sr=47331370
Recent Discussions
Related Content
* 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