Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Loadbalance a URL to 3 URLs

ASMAPMLTM
Altostratus
Altostratus

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

 

 

 

6 REPLIES 6

ragunath154
Cirrostratus
Cirrostratus

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
}
}

Paulius
MVP
MVP

@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?

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.

Its redirection only. 

ASMAPMLTM
Altostratus
Altostratus

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
}
}
}