Forum Discussion
Stephane_87808
Nimbostratus
Nov 20, 2009Assign a Pool AND rewrite an url
Hello
Is there a way :
- to assign a POOL of servers
and
- to rewrite the URL (adding a /xx.htm)
when a condition is matched in a irule ?
(of course, I will not declare any Default Pool of server for the corresponding VS)
As we need to start multiple webservers running on differents http ports (http://inter1.alk.com:8031/inter1, http://inter2.alk.com:8032/inter2, http://inter3.alk.com:8033/inter3, etc....), I would like to use only ONE VS and have the benefit from the irule capabilities to select the right pool of servers.
in addition, all the pools of servers we have defined can be the exact same servers, with the same ip addresses : the differents pools are only there to declare the differents ports we will use.
In the example below, the line "pool ..." only means what I would expect.
----------------------------------------
when HTTP_REQUEST {
if {[HTTP::host] equals "inter1.alk.com" and [HTTP::uri] equals "/" }
{
pool Pool_inter1
HTTP::redirect http://[getfield [HTTP::host] ":" 1]:8030/inter1
}
elseif {[HTTP::host] equals "inter2.alk.com" and [HTTP::uri] equals "/"}
{
pool Pool_inter1
HTTP::redirect http://[getfield [HTTP::host] ":" 1]:8031/inter2
}
}
----------------------------------------
Thanks for any help / advice
Stéphane
1 Reply
- hoolio
Cirrostratus
Hi Stéphane,
HTTP::redirect will result in LTM sending the client a 302 redirect to the new location. It sounds like you want to rewrite the URI. You can do this using HTTP::uri:when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method request to [HTTP::host][HTTP::uri]" Check if the URI is / if {[HTTP::uri] eq "/"} { log local0. "[IP::client_addr]:[TCP::client_port]: Matched URI check for /" Check the requested host (set to lower case) switch [string tolower [HTTP::host]] { "inter1.alk.com" { log local0. "[IP::client_addr]:[TCP::client_port]: Matched inter1." pool Pool_inter1 HTTP::uri "/inter1" } "inter2.alk.com" { log local0. "[IP::client_addr]:[TCP::client_port]: Matched inter2." pool Pool_inter2 HTTP::uri "/inter2" } default { log local0. "[IP::client_addr]:[TCP::client_port]: No match on Host header value" } } } }
This example checks for a URI of /, then sets the Host header value to lower case and checks for inter1.alk.com or inter2.alk.com. The corresponding pool is then selected and the URI is rewritten to /inter where is 1 or 2.
You may want to consider handling the default case where someone requests a different host header (or IP address) with a URI of /. That wouldn't be modified by this rule and would be sent to the default pool on the VIP if one is configured.
You can check the /var/log/ltm output from the debug logging. Once done testing either comment out or remove the debug log statements.
Aaron
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
