Forum Discussion
Redirecting request based on port number
I have two application servers as pool members to multiple pools. I want to be able to load balance based on port.
For example, If a user click first link, load balance staging pool. If user is in staging_pool and if user decides connect to development_pool from there, click the link that is in staging application.
Note: This is working currently but because I have to create Virtual Server for each pool. I don't want that.
when HTTP_REQUEST {
switch -glob [HTTP::host] {
http://example.mtd.today.com:8088/tuesday/ { pool Stagin_Pool }
http://example.mtd.today.com:8089/wednesday/ { pool Management_Pool }
http://example.mtd.today.com:8090/thursday/ { pool Development_Pool }
http://example.mtd.today.com:8091/friday/ { pool Test_Lab_Pool }
default { pool Production_Pool }
}
}
Thanks for your help.
18 Replies
- Elias_O_16228
Nimbostratus
Default error fixed. - Kevin_Stewart
Employee
The switch conditionals will evaluate what is sent to them. If you send "[TCP::local_port][string tolower [HTTP::uri]]" then the conditionals will see a port and a URI (ex. "8088/tuesday"). Because you're doing -glob on the switch, the example string will satisfy the first condition ("8088*") regardless of the URI. In fact nothing past the port number will matter at all because of the wildcard, so "[string tolower [HTTP::uri]]" has no effect at all.
If you still need to evaluate the URI, then your conditional should look something like this: "8088/tuesday*". If you care about the case of the URI, then just remove the [string tolower ] syntax. - Colin_Walker_12Historic F5 AccountIt sounds like what you're looking for is something like:
when HTTP_REQUEST { switch -glob [TCP::local_port][string tolower [HTTP::uri]] { "8088/tuesday*" { pool Stagin_Pool } "8089/wednesday*" { pool Management_Pool } "8090/thursday*" { pool Development_Pool } "8091/friday*" { pool Test_Lab_Pool } default { pool Production_Pool } } }
This would allow you to evaluate on the port and URI, regardless of the hostname. Is that what you're looking for?
As Kevin said, above, if you want to specifically match case and send individually cased URIs to different locations, then simply remove the string tolower command that's affecting the HTTP::uri, and then add multiple cases for those, such as:
...
"8088/tuesday*" { pool Stagin_Pool }
"8088/TUESDAY*" { pool ALLCAPS_Pool }
...
Colin - Elias_O_16228
Nimbostratus
Colin,
That is exactly what I am trying to accomplish. The application developer has confirmed case sensitive does not matter. I will test and confirm later when I got a breading space.
Thanks all - Elias_O_16228
Nimbostratus
Hi guys,
Can we revisit this issue once again?
To make it easier I decided to use port numer only for internal testing purpose rather than URL. Assumption is that if port works, then I will use URL
Below is the port only irule based on F5 training manual. It uses "switch". There is no error on this irule but it's not function as intended. Only the default pool dba_pool is working. Again, the pool member IP address is the same.
when CLIENT_ACCEPTED {
set MYPORT [TCP::local_port]
log local0. "Port is $MYPORT"
switch $MYPORT {
895 {
pool app_Dev_Pool
}
891 {
pool C_Dev_Pool
}
894 {
pool java_Dev_Pool
}
902 {
pool web_Dev_Pool
}
890 {
pool oracle_Dev_Pool
}
default {
pool dba_Dev_Pool
}
}
}
Thanks for your help. - Elias_O_16228
Nimbostratus
Below is the config snario:
Virtual Server 10.10.10.9
service port: 8088
Resource: default Pool dba_Dev_Pool
pool app_Dev_Pool
member 10.10.10.10:895
member 10.10.10.10:895
pool C_Dev_Pool
member 10.10.10.10:891
member 10.10.10.10:891
pool java_Dev_Pool
member 10.10.10.10:894
member 10.10.10.10:894
pool web_Dev_Pool
member 10.10.10.10:902
member 10.10.10.10:902
pool oracle_Dev_Pool
member 10.10.10.10:890
member 10.10.10.10:890
pool db_Dev_Pool
member 10.10.10.10:8088
member 10.10.10.10:8088
No Virtual Servers for these pools except the default. - nitass
Employee
set MYPORT [TCP::local_port]TCP::local_port in CLIENT_ACCEPTED will return virtual server port number (i.e. 8088).
you may change virtual server port number to any (*) and let client choose which port to connect to. so, irule will direct client traffic to pool based on the port number. - Elias_O_16228
Nimbostratus
Thanks Nitass,
Waoo! It worked! This could be reason the URL "switch glob" was not working. I think my troubleshooting strategy is working. I saw my hair look like Albert Einstein.
Cheers
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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