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 cou...
hoolio
Cirrostratus
Jul 17, 2009I'm guessing you don't want to redirect the client. If you did, the client would see the change, try to resolve www.apacheserver.com to an IP address and then make a new request to that IP. To rewrite the host header and URI you could use an iRule like this:
when HTTP_REQUEST {
log local0. "[IP::client_addr][TCP::client_port]: New request to [HTTP::host][HTTP::uri]"
switch [string tolower [HTTP::host]] {
"www.site1.com" {
Rewrite host to www.apacheserver.com
HTTP::header replace Host "www.apacheserver.com"
Prepend /site1 to the URI
HTTP::uri "/site1[HTTP::uri]"
}
"www.site2.com" {
Rewrite host to www.apacheserver.com
HTTP::header replace Host "www.apacheserver.com"
Prepend /site2 to the URI
HTTP::uri "/site2[HTTP::uri]"
}
"www.site3.com" {
Rewrite host to www.apacheserver.com
HTTP::header replace Host "www.apacheserver.com"
Prepend /site3 to the URI
HTTP::uri "/site3[HTTP::uri]"
}
default {
Take some default action?
}
}
}
when HTTP_REQUEST priority 501 {
This event is added for debug only. It bypassed the variable caching for HTTP::host and HTTP::uri
log local0. "[IP::client_addr][TCP::client_port]: Updated request to [HTTP::host][HTTP::uri]"
}
If the application uses absolute references to www.apacheserver.com in response headers and/or content you could rewrite them using 'HTTP::header replace' and/or a stream profile and STREAM::expression based iRule, respectively.
Aaron
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