Forum Discussion
Name Based Hosting iRule not working
Hi Folks,
My company hosts a bunch of sites on a single virtual server. Each website has its own pool and health monitor. I decided to use this irule to forward the request to the appropriate pool based on the host url.
when HTTP_REQUEST {
ABC-DG-Test is a string data-group where the entries are name:value pairs
name is the requested HTTP host header, value is the associated pool-name
check the requested HTTP host header against entries in data-group ABC-DG-Test
if { [class match [string tolower [HTTP::host]] equals ABC-DG-Test ] } {
if the HTTP host header is in ABC-DG-Test
send the request to the pool associated with the ABC-DG-Test entry
pool [class match -value [string tolower [HTTP::host]] equals ABC-DG-Test ]
} else {
drop the request if the host header is not in ABC-DG-Test
drop
event disable
}
}
The problem is that if the url that comes in is abc.com it will forward to the abc pool. If the url is abc.com/blah it will only display the page for abc.com and not abc.com/blah. The website shows correctly if you hit the web server node.
Any help or suggestions would be appreciated.
Thanks,
Kevin
3 Replies
- Brad_Parker
Cirrus
A.) don't use drop, you are better to use
if you have upstream devices. If your LTM is at the edge then it should be fine.reject2.) Why are you disabling the event? Do you have additional HTTP_REQUEST iRules? Your pool selection should have no effect on the requested URI.
- VernonWells
Employee
By the way, if you are using at least 11.4, you may consider using Local Traffic Policies for this:
If you are using a version before 11.4, Traffic Classes can be used:
An example of a Local Traffic Policy to direct queries for www.abc.com to pool1 and www.xyz.com to pool2:
ltm policy policy-hostname-redirect { controls { forwarding } requires { http } rules { www.abc.com { actions { 0 { forward select pool pool01 } } conditions { 0 { http-host values { www.abc.com } } } ordinal 1 } www.xyz.com { actions { 0 { forward select pool pool02 } } conditions { 0 { http-host values { www.xyz.com } } } ordinal 2 } } strategy first-match }Naturally, this can be done via the Web UI, as well.
- bizooga
Nimbostratus
Hi Guys,
Looks like this is a false alarm. After finally getting a hold of my development team (these websites are custom in house apps), it appears that the application is hard coded to do some redirection. I'm going to try to convince them to stop doing that so my iRule will correctly. Thanks for all your help.
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