Forum Discussion
irule pool redirect based on port and host header
I would like to setup a single virtual server with the sevice port set to 0 (all) and i'd like to make sure it only services certain ports, for now 80/443, but i could potentially build it out more. So I have a couple of questions.
1) Does the 'when HTTP_REQUEST' filter based on port or traffic type 2) Should/can i nest events - CLIENT_ACCEPTED/HTTP_REQUEST? 3) How would i add an if port is 123 go to pool_test_123, based on question 1, if this it HTTP traffic does the HTTP_REQUEST apply?
I have this iRule currently and its fine, but it doesnt take in to account any odd ball ports, so im not sure what the best way to construct this is. I saw this https://devcentral.f5.com/questions/virtual-server-multiple-service-ports and wasnt sure if i had to nest the events or handle them separately.
Here is the current iRule that only takes in to account 80/443 (i think)
when HTTP_REQUEST {
build pool name from header, Pool_Sub_Port
set hostpool pool_[string tolower [getfield [HTTP::host] "." 1]]_[TCP::local_port]
if { [catch {pool $hostpool} exc] } {
host header doesnt match a pool, send to default http/https pool
if{ [catch {pool pool_www_[TCP::local_port]} exc]} {
if for some reason the port isnt 80/443 go to 80
pool pool_www_80
}
}
}
1 Reply
- Kevin_Stewart
Employee
1) Does the 'when HTTP_REQUEST' filter based on port or traffic type
The HTTP events and commands are enabled when you apply an HTTP profile to the virtual server. It doesn't really matter what the actual port is, as long as the HTTP "filter" can detect HTTP-specific protocol data in the TCP payload.
2) Should/can i nest events - CLIENT_ACCEPTED/HTTP_REQUEST?
These events generally operate at different layers of the stack, so it's absolutely useful to use them both in a single iRule. How you use them depends on what you're trying to do though.
3) How would i add an if port is 123 go to pool_test_123, based on question 1, if this it HTTP traffic does the HTTP_REQUEST apply?
The important thing to understand here is the notion of connection-based context. In other words, context is based on a TCP connection/session. A CLIENT_ACCEPTED event happens first and can see all of the data at layer 4 (TCP payload, IP addresses, etc.). An HTTP_REQUEST event is triggered at layer 7 and can see all of the HTTP-specific protocol data - plus all of the data collected in earlier layers. So the following would be useful:
when HTTP_REQUEST { if { [TCP::local_port] equals "123" } { pool test_123_pool } else { pool normal_pool } }
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