Forum Discussion
Luca_55898
Jun 27, 2011Nimbostratus
Redirect to TCP port based on URL
Hello,
We have an Alteon load balancer that will be replaced with an LTM very soon.
We have a pool of two servers which run a bunch of different websites. The sites all use the same domain name, but just load different pages such as,
www.website.com/employees
www.website.com/customers
www.website.com/new_users
The servers run on an Apache host which knows what page to loaded based upon the TCP port people come in on. Currently the Alteon redirects incomming traffic to use either port 80,81 or 82 depending on which URL is entered into a browser.
So, can i create an iRule which will look at the incoming URL, then redirect traffic to the pool on either TCP 80,81, or 82?
I'm very new to iRules so if someone could point me in the right direction that would be good.
I know i could create a VIP for each site, but there are more than three and each requires HTTP and HTTPS so we would need a lot of VIPs. I'd also like to get my hands dirty with iRules.
So i know how to get started, just not how to redirect to a port.
when HTTP_REQUEST {
if {[HTTP::uri] equals {www.site1.com/test}} {HTTP::uri {www.site.com/test:81}
}
}
thoughts?
- Peter_72728NimbostratusFirst, I noted that you were testing [HTTP::uri] for a match to "www.site1.com/test". Assuming that "www.site1.com" is the domain, that would never be true because [HTTP::uri] only contains the path and querystring parts of the URL. Take a look at the page below...It should help clarify the portions of a URL (i.e. HTTP::host, HTTP::uri, etc).
- hooleylistCirrostratusPeter's rule looks like a good start. You could use that rule on an HTTP and an HTTPS virtual server for whatever www.site1.com resolves to.
- hooleylistCirrostratus...
- Luca_55898NimbostratusThanks for the info.
- hooleylistCirrostratusIf you don't want to use a default pool on the virtual server, you'd want to ensure that you assign a pool in each case in the switch statement:
when HTTP_REQUEST { switch -glob [HTTP::uri] { "/employees*" { pool pool-81 } "/customers*" { pool pool-82 } "/new_users*" { pool pool-83 } default { pool pool-80 } } }
- Ryan_Paras_7933NimbostratusYou may want to explore using datagroups (classes) so that you don't have to edit the irule every time you want to add or remove a URI/pool combo.
- hooleylistCirrostratusNice idea, Ryan. You could also use URI::path to save a bit on parsing the first directory:
- Luca_55898NimbostratusThanks for the help guys. I have it working using the iRule hoolio provided.
- hooleylistCirrostratusIf you want to drop the requests which don't match, it's much cleaner to use the default case to call the drop command. You could leave it out but then I think you'd need a OneConnect profile.
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