Forum Discussion
Greg_76561
Nimbostratus
Jan 28, 2011Route to different pools based on /content
Hello,
I'm new to iRules and trying to come up with a way to send traffic to different pools based on the /content in the url.
I have a secure site which the ssl certificate is installed on the LTM and from there it is non-secure to the server.
I would like to set it up to where when a user goes to https://www.domain.com/QA they go to one pool. If a user goes to https://www.domain.com/UAT they go to a different pool and if they go to https://www.domain.com/Prod they go to a third pool. The path might actually be longer than these but we should be able to key off of QA, UAT and Prod and send it to the appropriate pool that way.
Any help would be greatly appreciated.
Thanks
Greg
15 Replies
- hoolio
Cirrostratus
Hi Greg,
You can use HTTP classes or an iRule to do this. With HTTP classes, (in the GUI under Profiles : Protocol : HTTP Class) you'd create one class per pool and configure the URI's with string matching in the URI Paths section. Here is a view of the config from the bigip.conf:profile httpclass qa_class { defaults from httpclass pool qa_pool redirect none paths { "/QA*" "/qa*" } } profile httpclass uat_class { defaults from httpclass pool uat_pool redirect none paths { "/UAT*" "/uat*" } }
Note that I'm assuming the app isn't case sensitive and you'd want /UAT and /uat to both go to the same pool. You could add a final HTTP class with no filters and specify a pool for all URIs which don't match a prior HTTP class.
Here is an example of an iRule to select between pools based on the URI:when HTTP_REQUEST { Check URI set to lower case with wildcard matching switch [string tolower [HTTP::uri]] { "uat*" { uat_pool } "qa*" { qa_pool } default_pool { qeneral_pool } } }
Aaron - Greg_76561
Nimbostratus
Thanks for all the information. That worked great but apparently I was misinformed on part of what they are wanting. They actually want the QA, UAT or Prod removed from the string when it is sent on to the pool. So if you went to https://www.domain.com/QA/Signon.jsp they want it sent to the QA pool but they want the QA removed from the string but keep everything after that.
Thanks again for all your help.
Greg - JRahm
Admin
How about:HTTP::uri [string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end] % set uri "/QA/Signon.jsp" /QA/Signon.jsp % string range $uri [string first "/" $uri 1] end /Signon.jsp - Greg_76561
Nimbostratus
Would there be a way to do this to just remove the QA, UAT or Prod from the url without having the full path defined within the iRule. It would be a little cleaner and easier to manage as there could be additional paths that need to get added later on and would rather not have to keep adding rules as they add additional paths.
Also, is there a best practice as far as how to implement the iRules? When doing multiple things (sending trafifc to different pools based on uri and removing part of the url) do you want to use one iRule or do you just keep them separate?
Thanks,
Greg - JRahm
Admin
What do yo mean defining the path? As far as best practices go, there are trade-offs between readability and manageability. If you aren't doing too much, it makes sense to be lumped into one iRule. If there are a crazy number of lines and functions, it might make more sense to split them out. - Greg_76561
Nimbostratus
If, for example, today we had a client going to http://www.domain.com/QA/Signon.jsp and then a month from now development added a second link such as http://www.domain.com/QA/secondpage.jsp I would rather, if possible, to have it set up to send it on to the QA pool as http://www.domain.com/Signon.jsp and http://www.domain.com/secondpage.jsp respectively without having to modify the iRule each time they add a new path. So the iRule would just look for the QA, in this example, to know it needs to send it to the QA pool and then remove the QA from the path before it sends it on. Hopefully that makes a little more sense.
Thanks,
Greg - JRahm
Admin
oh, I think you misunderstood my example. After the first line, I just demonstrate the string command in a native tcl shell. This is the only thing that is actual iRule code:
HTTP::uri [string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end]
You'll want to make sure you use this only in the switch cases though so it doesn't arbitrarily pull path information out of all URIs. - Greg_76561
Nimbostratus
I must not be doing something right when trying to tie the two together in one iRule. How do you incorporate the two sections below in to one iRule? When I've tried combining the two it will send it on to the pool but it won't strip off the /QA.
Section 1:
when HTTP_REQUEST {
Check URI set to lower case with wildcard matching
switch [string tolower [HTTP::uri]] {
"uat*" {
uat_pool
}
"qa*" {
qa_pool
}
default_pool {
qeneral_pool
}
}
}
Section 2:
HTTP::uri [string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end]
Thanks for your patience,
Greg - Chris_Miller
Altostratus
You'll have to put section 2 inside of each match in your switch statement, i.e."qa*" { qa_pool HTTP::uri [string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end ] } - Greg_76561
Nimbostratus
Thanks Chris. I tried doing that and it did not strip out the /QA, /UAT or /Prod. The url never gets altered.
Greg
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
