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.
- JRahm
Admin
Yep, that's doable. Do you have a requirement of the name (ie. webserver1), or do you want to redirect even if it's something like just-trying.domain.com/SITE1? Also, does the case of the SITE1 matter? Do you have specific sites in mind, or will the site always be the first word in the path? - Matt_108113
Nimbostratus
So this Virtual server on the F5 is a one to one ratio so I am not load balancing or anything so I don't need the webserver name as a requirement, so if they hit. - Sebas_82058
Nimbostratus
Hi guys, I am working with Matt on this issue and the issue is this. - hoolio
Cirrostratus
I'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]" }
- Sebas_82058
Nimbostratus
Great! Let me try this out. - Sebas_82058
Nimbostratus
Awesome! This works great! - hoolio
Cirrostratus
Are you actually filtering on the requested host header value? If not, you could remove the HTTP::header replace Host command from the iRule. - Sebas_82058
Nimbostratus
No, there are no filters in place. I will remove it and test. - Bill_Callahan_8
Nimbostratus
Can you set a variable based on the HTTP::host and use that variable so you don't have to specify each site? - Sebas_82058
Nimbostratus
Removed it and also removed the lines for debugging.
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