Forum Discussion
JimB_43720
Apr 14, 2011Nimbostratus
Change destination port based on hostheader
I wondered if I could use an irule to change the destination port of a standard http request based purely on the hostheader?
The current setup is as follows:
We are using BIG IP 9.4.4.
Standard http requests for multiple sites are sent to a single vserver, (DNS Aliases are used to conserve ip addresses). (Only port 80 is allowed for inbound traffic).
Is there an iRule that would acheive the following;
if the hostheader is URL_A the port should be changed to port 81 on any of the physical servers in the pool
AND
if the hostheader is URL_B then the port should be changed to port 82 on any of the physical servers in the pool.
Cheers
Jim
- James_Quinby_46Historic F5 AccountOne way to do this would be with 2 separate pools - one for the the port 81 apps, and the other for the port 82 apps. Then you could do something like this:
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { www.foo.com { pool port_81_servers } www.bar.com { pool port_82_servers } } }
- JimB_43720NimbostratusCheers for the reply jquinby.
- James_Quinby_46Historic F5 AccountJim - all you need to do is create the virtual, the two pools and apply the iRule. It's not necessary for a VS to have a pool assigned. One of the mainstay, canonical rules is an HTTP to HTTPS redirect. It's applied to a VS listening on port 80, issues a 302 redirect to the same host on port 443, and has no additional resources applied beyond the iRule.
- JimB_43720NimbostratusCool.
- James_Quinby_46Historic F5 AccountPosted By JimB on 04/14/2011 08:07 AM Cool.
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { www.foo.com { pool port_81_servers } www.bar.com { pool port_82_servers } }
default { pool whatever_your_default_pool_is }
}
- JimB_43720NimbostratusCheers Jquimby that worked a treat after I dropped the default pool line.
- hoolioCirrostratusA closing brace was just on the wrong line. You could also dynamically get the VS default pool name rather than hard coding it in the iRule:
when CLIENT_ACCEPTED { Save the name of the VS default pool before it's modified in this iRule set default_pool [LB::server pool] } when HTTP_REQUEST { switch [string tolower [HTTP::host]] { www.foo.com { pool port_81_servers } www.bar.com { pool port_82_servers } default { pool $default_pool } } }
- JimB_43720NimbostratusThanks Hoolio
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