Forum Discussion
titan_101505
Nimbostratus
Jan 18, 2016URL request rewrite with load balance
we need redirect traffic to below 2 URLs with round robin load balance method
do you know what is the simplest method to fulfill this scenario ?
thanks
Kai_Wilke
MVP
Jan 19, 2016Hi Titan,
the iRule below performs a simple round robin redirect to either server1 or server2...
when RULE_INIT {
set static::report_nodes "server1 server2"
}
when HTTP_REQUEST {
set random_report_node [lindex $static::report_nodes [expr {int(rand()*[llength $static::report_nodes])}]]
HTTP::redirect "http://$random_report_node/Reports_MSSQLSERVER12/Pages/Folder.aspx?ItemPath=%2fReports&ViewMode=List"
}
If you want to health-monitor your report servers, so that clients are not getting redirected to offline nodes, then you have to create a pool and some health-monitors for your report servers. The iRule below can then be used to randomly select an available report server...
when RULE_INIT {
array set static::report_server_names {
"192.168.1.1%1 80" "server1"
"192.168.1.2%1 80" "server2"
}
}
when HTTP_REQUEST {
if { [active_members POOL_REPORT_SERVERS] > 0 } then {
set active_report_nodes [active_members -list POOL_REPORT_SERVERS]
set random_report_node [lindex $active_report_nodes [expr {int(rand()*[llength $active_report_nodes])}]]
HTTP::redirect "http://$static::report_server_names($random_report_node)/Reports_MSSQLSERVER12/Pages/Folder.aspx?ItemPath=%2fReports&ViewMode=List"
} else {
HTTP::redirect 200 content "The report server are offline..."
}
}
Cheers, Kai
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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