Forum Discussion
Matt_108113
Nimbostratus
Jul 15, 2009Using Irules to mimic apache Virtual hosts
I would like to use I rules to mimic Apache Virtual Hosts.
I have a web server that has a bunch of sites on it and instead of setting up virtual hosts on Apache I wanted to see if I could do this with Irules.
Basically when someone hits the site and requests http://webserver1.domain.com/SITE1 they would be redirected to.
http://SITE1.domain.com in the browser.
there are multiple sites and they are added all the time so if I could get something generic like.
when HTTP_REQUEST {
if { [HTTP::uri] contains "/SITE1" }{
HTTP::redirect http://site1.domain.com}
}
Is kind of the idea, but how to I make the F5 aware that site1 is on the webserver at http://webserver1.domain.com/SITE1?
The problem is I don't know syntactically what needs to be were to do this.
Any help would be appreciated.
11 Replies
- JRahm
Admin
@bcallahan, yes you could do something like this:
[getfield [domain [HTTP::host] 2] 1]
or
[lindex [split [HTTP::host] .] end-1]
Either of these would take string a string value from HTTP::host of www.site1.com and return only site1
So the rule could be consolidated to:when HTTP_REQUEST { HTTP::header replace Host "www.apacheserver.com" HTTP::uri "/[getfield [domain [HTTP::host] 2] 1][HTTP::uri] }
With this approach, you might build a class of acceptable websites to compare against to keep noise from hitting your servers. Same principle as Hoolio suggested with the default case in the switch.
HTH...Jason
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
