Forum Discussion
abeny_894
Nimbostratus
Dec 12, 2008HTTP::uri problem
Deal all,
I have got some problems on [HTTP::uri], for example:
_________________________________________________________
http://www.foo.com/development/ --> Pool 1
http://www.foo.com/marketing/ --> Pool 2
http://www.foo.com/support/ --> Pool 3
when HTTP_REQUEST {
if {[HTTP::uri] starts_with "/development" } {
pool pool_development
} elseif {[HTTP::uri] starts_with "/marketing" } {
pool pool_marketing
} elseif {[HTTP::uri] starts_with "/support" } {
pool pool_support
}
else {
discard
}
}
______________________________________________________________
I found that the request is directly go to find the DEFAULT PAGE of http://www.foo.com/development/ rather than go to access the development pool
Is it the normal behaviour??
In fact I need to check the HTTP::uri in HTTP_REQUEST, if uri is match /development, it will go to development pool, however all members in development pool is using port8080.
Can give me some advise??
10 Replies
- hoolio
Cirrostratus
A switch statement might be easier to manage than a chain of if/elseif/else statements. You can add logging to see what's happening:when HTTP_REQUEST { Check the requested URI switch -glob [HTTP::uri] { "/development*" { log local0. "[IP::client_addr]:[TCP::local_port]: [HTTP::uri] matched /development" pool pool_development } "/marketing*" { log local0. "[IP::client_addr]:[TCP::local_port]: [HTTP::uri] matched /marketing" pool pool_marketing } "/support*" { log local0. "[IP::client_addr]:[TCP::local_port]: [HTTP::uri] matched /support" pool pool_support } default { log local0. "[IP::client_addr]:[TCP::local_port]: [HTTP::uri] hit default case" reject } } }
If this doesn't work as expected, can you check the /var/log/ltm log file and post the log output?
Aaron - abeny_894
Nimbostratus
Thanks Aaron, I try it and get back you soon - abeny_894
Nimbostratus
Hi Aaron,
I have modify the iRules as below and logged after enable the VS, seems the result is not expected:
Case1: http://fedora.abc.com/app1 ---> go to the port 80 and default page of app1 (web1_pool_80)
Case2: http://fedora.abc.com/app2 ---> go to the port 8080 and default page of app2 (web1_pool_8080)
Case3: http://fedora.abc.com/app3 ---> go to the port 80 and default page of app3 (pool web2_pool_80)
However, the iRules is not load balance the traffic to the pool, it seems find the exactly match path under what URI defined in the [HTTP::uri], if not match, it returns 404 page not found. It is the normal behaviour?? Thanks for your help
_______________________________________________________________
when HTTP_REQUEST {
Check the requested URI
switch -glob [HTTP::uri] {
"/app1*" {
log local0. "[IP::client_addr]:[TCP::local_port]: [HTTP::uri] matched /app1"
pool web1_pool_80
}
"/app2*" {
log local0. "[IP::client_addr]:[TCP::local_port]: [HTTP::uri] matched /app2"
pool web1_pool_8080
}
"/app3*" {
log local0. "[IP::client_addr]:[TCP::local_port]: [HTTP::uri] matched /app3"
pool web2_pool_80
}
default {
log local0. "[IP::client_addr]:[TCP::local_port]: [HTTP::uri] hit default case"
reject
}
}
}
________________________________________________________________
Dec 15 09:53:29 tmm tmm[1736]: Rule iRules_test1215 : 172.167.14.33:80: /app1 matched /app1
Dec 15 09:53:37 tmm tmm[1736]: Rule iRules_test1215 : 172.167.14.33:80: /app2 matched /app2
Dec 15 09:53:45 tmm tmm[1736]: Rule iRules_test1215 : 172.167.14.33:80: /app3 matched /app3
Dec 15 09:53:51 tmm tmm[1736]: Rule iRules_test1215 : 172.167.14.33:80: /sales hit default case
_____________________________________________________________
FYI, if i use [HTTP::host], no such problem found and it can successfully load-balance to the said pool. - abeny_894
Nimbostratus
Hi all,
Anybody can help on this? Thank you - hoolio
Cirrostratus
Hi Abeny,
I'm not sure what the problem you're seeing is. Can you explain more on what is failing and what you want to happen instead?
Thanks,
Aaron - abeny_894
Nimbostratus
Thanks Aaron.
I just thinking is it the normal behavour for:
switch [HTTP::uri] {
"/development" { log local0. "[IP::client_addr]:[TCP::local_port]: [HTTP::uri] matched /development"
pool pool_development
When request is hit http://xxx.com/development, it is match the iRule, and the traffic will go to pool_development, however, it will go to find the exactly path page ( /development ) in the pool members. If I changed the pool from pool_development to pool_irules, the result will return 404 page not found. It is becase under pool_irules, all pool members haven't contain the path /development and page.
So I would like to ask, is it the normal result for using [HTTP::uri]?? Thank you so much - hoolio
Cirrostratus
If you don't use -glob and add a wildcard to the /development case (like /development*), the case will only match when a client makes a request for exactly /development. If you want all requests which start with /development to go to the pool_development, you could use -glob and a wildcard:switch -glob [HTTP::uri] { "/development*" { pool pool_development } ...
I'm not sure what you mean by "however, it will go to find the exactly path page ( /development ) in the pool members". The iRule isn't modifying the URI--it's just selecting the pool based on the URI.
Aaron - andy_22730
Nimbostratus
Hello:
I want to do something similar, but I want to redirect certain URI's and Proxy (via a pool) others...
I don't seem to be able to use both the HTTP::redirect within the same irules as forwards to pools.
How can I do this?
For instance:
if {[HTTP::uri] starts_with "foo"} {HTTP::redirect "http://foo.com"}
if {[HTTP::uri] starts_with "bar"} {pool bar-pool}
I can create this irule, but anytime it matches to the bar, I get a tmm error about redirecting.... - hoolio
Cirrostratus
dillera, can you start a new post about this? I assume one way or another you're trying to send more than one redirect to the client either in the first rule or in another rule that's added to the same VIP. For suggestions on how to handle this try searching this forum for a relevant portion of the error message, like 'multiple redirects error'. If you get stuck, you could start a new post detailing the full iRule configuration for the particular VIP.
Aaron - andy_22730
Nimbostratus
ok, will do.
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
