Forum Discussion

Carolyn_Robert_'s avatar
Carolyn_Robert_
Icon for Nimbostratus rankNimbostratus
Dec 12, 2006

Redirecting to a pool

I'm confused about how to use redirects and pooling.

 

 

Here's my situation:

 

> DNS entry "www.abcd.com" is pointed at my virtual server "gateway"

 

> VS "gateway" uses pool "PROD", that contains two nodes, "website1" & "website2"

 

> I need to actually redirect from http to https using the two nodes in the pool while at the same time modifying my URI.

 

 

Here's a piece of code:

 

 

when HTTP_REQUEST {

 

if { ([HTTP::host] equals "www.abcd.com") } {

 

HTTP::uri /xyz.html

 

pool PROD

 

HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]

 

}

 

}

 

 

The [HTTP::host] substitution does not work, because the host needs to be modifed by whichever node the pool picks. So my final URL would be either:

 

 

https://website1.abcd.com/xyz.html

 

OR

 

https://website2.abcd.com/xyz.html

 

 

depending on what the pool determines is the next available candidate for work.

 

 

How can I figure out what node is selected by the pooling function so that I can build the full URL for the redirect statement?

1 Reply

  • I don't think it will work to select the pool and redirect in the same shot.

    If you have HTTP and HTTPS virtual servers that www.abcd.com points to, you could redirect all clients to https://www.abcd.com. Then on the HTTPS virtual server you could rewrite the Host header to the host name of the selected node.

    You could use this rule on the HTTP virtual server to redirect from HTTP to HTTPS:

    
    when HTTP_REQUEST {
      HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
    }

    For the HTTPS VIP, you would need to assign a client SSL and HTTP profile. You could then use the following rule as an example to rewrite the host header after the node has been selected, but before the request is sent to the node.

    
    when LB_SELECTED {
       if { [IP::addr [LB::server addr] equals 10.0.0.10] }{   
          HTTP::header replace Host "new_http_host_header.example.com"
          log local0. "Replaced host header with value 1"
       }
       elseif {[IP::addr [LB::server addr] equals 10.0.0.20] }{
          HTTP::header replace Host "second_new_http_host_header.example.com"
          log local0. "Replaced host header with value 2"
       }
       else {
           take some default action?
          pool default_pool
          log local0. "Took some default action"
       }
    }

    I haven't tested this but in concept it should work. If you run into problems/errors, check the /var/log/ltm log file for the entries and repost if you need any help.

    You can check the LB::server page on the wiki for more details on the related LB::server (Click here) and IP::addr commands (Click here)

    Aaron