Forum Discussion
Loadbalance a URL to 3 URLs
Hi Guys,
I have a requirement like
when HTTP_REQUEST {
if { [HTTP::path] equals "/exampletext"
it should loadbalance/roundrobin the redirection to 3 URLs shown below
"https://abc1ee.xyz.com/exampletext_1"
"https://abc2ee.xyz.com/exampletext_2"
"https://abc3ee.xyz.com/exampletext_3"
Kindly, help ! TIA
- ragunath154Cirrostratus
you can use the RAND funtion in irule ,try below irule
when HTTP_REQUEST {
# Generate a random number between 1 and 3
set random_num [expr {int(rand() * 3) + 1}]
if {[string tolower [HTTP::path]] eq "/exampletext"} {
HTTP::redirect http://abc$random_num\ee.xyz.com/exampletext_$random_num
}
} ASMAPMLTM you can use ragunath154 example but that will be random load balancing using the random function rather than round robin. Why do you have the requirement to load balance the host portion rather than allowing the use of 1 host and then load balancing to all servers that would handle request from the 3 seperate hosts?
- ASMAPMLTMAltostratus
Well I agree this scenario is different than the ideal solution. Its what application team is pushing.
Is this something related with Openshift service url. Because I'm getting confused when you say redirect. Do you want redirect or host header modify & send the traffic to your respective servers which handle each domains.
- ASMAPMLTMAltostratus
Its redirection only.
- ASMAPMLTMAltostratus
This worked, but dont sometimes it fails out of nowhere
when RULE_INIT {
set ::c 0
}
when HTTP_REQUEST {
event enable
switch $::c {
0 {
HTTP::redirect "https://abc1ee.xyz.com/exampletext_1"
incr ::c
event disable
}
1 {
HTTP::redirect "https://abc2ee.xyz.com/exampletext_2"
incr ::c
event disable
}
2 {
HTTP::redirect "https://abc3ee.xyz.com/exampletext_3"
set ::c 0
event disable
}
}
}
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