Forum Discussion
richard_polyak
Jun 04, 2024Altocumulus
VS with Wildcard Pool set path to specific port
Good Day - Today we have a Virtual Server listening on port 443, and an irule with 300+ lines to switch pool based on the path. Example of current irule is below: when HTTP_REQUEST { swit...
spalande
Jun 12, 2024Nacreous
Create datagroup (uri_to_port) for uri to port mapping
ltm data-group internal /Common/uri_to_port {
records {
"/service1" { data "7070" }
"/service2" { data "8080" }
"/service3" { data "9090" }
}
type string
}
create app_pool with pool members with wildcard port and then use below iRule
when HTTP_REQUEST {
# Default port if not found in data group
set port_number 443
# Get the URI path
set uri_path [HTTP::path]
# Lookup the port number in the data group
set port_number [class lookup $uri_path /Common/uri_to_port]
# optional logging
log local0. "Routing to port $port_number based on URI $uri_path"
# Get the list of pool members
set pool_members [members -list app_pool]
# Initialize a flag to indicate if a node is selected
set node_selected 0
# Iterate through pool members to find an active one on the specific port
foreach member $pool_members {
# Extract the IP address from the member string
set ip [lindex [split $member ":"] 0]
# Check if the node is active on the specified port
if {[active_members -node "$ip:$port_number"] > 0} {
# Node is active
set selected_member "$ip:$port_number"
set node_selected 1
break
}
}
# Check if a node was selected
if {$node_selected} {
#optional logging
log local0. "Selected member: $selected_member"
# Use the node command to forward traffic to the specific server and port
node $selected_member
} else {
# No active members found, respond 503
HTTP::respond 503 content "Service Unavailable"
}
}
PS - This isn't tested iRule. Please test in non-prod environment before proceeding to PROD.
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