cancel
Showing results for 
Search instead for 
Did you mean: 

iRule for pool usage instead of VIP(s)

Hector_Rodolfo
Nimbostratus
Nimbostratus

Hi team,

I quite new to iRule. And, I am trying to implement a common VIP, used to replace doing several independent VIPs.

So, instead of doing new VIPs, use their existing pools and only new pool(s)/node(s) will be added to the LLB.

The VIP common is "test-redirection.com", which uses the pools already made for other VIPs.

For example:

pool-service1-80

pool-service2-80

pool-service3-80

 

So, when it is used any of these URLs: 

http://test-redirection.com/service1.com/testing or,

http://test-redirection.com/service2.com/testing or,

http://test-redirection.com/service3.com/testing

 

Instead of using the pool for "test-redirection.com", the iRule use the pool for service"x".com (x = 1, 2 or 3)

So, the correct server be addressed and information provided.

 

I am doing the iRule, like this:

 

when HTTP_REQUEST {

  switch -glob [HTTP::uri] {

  "/service1*" {

   pool /Common/pool-service1-80

   }

  "/service2*" {

   pool /Common/pool-service2-80

   }

  "/service3*" {

   pool /Common/pool-service3-80

  } 

}

 

However, seems not to be working as expected.

It keeps answering with HTTP-404, URL not in this...

 

Any ideas, how to correct this behavior...

 

 

3 REPLIES 3

I would recommend you to use LTM policy for this redirection. But if you want to do it using iRules, you can try below iRule.

 

when HTTP_REQUEST { if { [HTTP::uri] starts_with "/service1" }{ pool pool-service1-80 } elseif { [HTTP::uri] starts_with "/service2" }{ pool pool-service2-80 } elseif { [HTTP::uri] starts_with "/service3" } { pool pool-service3-80 } }

 

Hector_Rodolfo
Nimbostratus
Nimbostratus

Thanks Mayur,

 

I tried but now, I am having the response:

 

Hmmmm.... can´t reach this page

The connection was reset.

Try:

 Checking the connection

 etc

 

Then, tried adding this; but, I think, it will still need the VIP (virtual server configuration) to perform the redirection

 

when HTTP_REQUEST {

 if { [HTTP::uri] starts_with "/service1" }{

  pool pool-service1-80

HTTP::redirect http://[HTTP::uri]

 } elseif { [HTTP::uri] starts_with "/service2" }{

  pool pool-service2-80

HTTP::redirect http://[HTTP::uri]

 } elseif { [HTTP::uri] starts_with "/service3" } {

  pool pool-service3-80

HTTP::redirect http://[HTTP::uri]

 }

}

 

then:

 

when HTTP_REQUEST {

 if { [HTTP::uri] starts_with "/service1" }{

HTTP::redirect http://[HTTP::uri]

  pool pool-service1-80

 } elseif { [HTTP::uri] starts_with "/service2" }{

HTTP::redirect http://[HTTP::uri]

  pool pool-service2-80

 } elseif { [HTTP::uri] starts_with "/service3" } {

HTTP::redirect http://[HTTP::uri]

  pool pool-service3-80

 }

}

 

If I use something like this, seems to work as expected; but, I think using this option:

the virtual server configuration is used, instead of only the pool confguration

 

when HTTP_REQUEST {

   switch -glob [HTTP::uri] {

   "/service1*" {

     pool /Common/pool-service1-80

     HTTP::redirect http://[HTTP::uri]

     return }

   "/service2*" {

     pool /Common/pool-service1-80

     HTTP::redirect http://[HTTP::uri]

     return }

   "/service3*" {

     pool /Common/pool-service1-80

     HTTP::redirect http://[HTTP::uri]

     return }

   } 

}

 

I´ll check your option about the policy...

Yes, you can try LTM policy. Regarding need of VIP for redirection, could you please confirm the port of VIP where the request will hit? Now if user will access http URL with default port and you want to redirect that request to the pool as per irule, then VIP with port 80 should be sufficient. Else if you want to redirect user request from http to https first then redirect it to the pool, in this case you would need two separate VIPs i.e. one will listen on port 80 and other will listen on 443. Hope it helps to achieve your requirements.