Forum Discussion

gh0std0g_79292's avatar
gh0std0g_79292
Icon for Nimbostratus rankNimbostratus
Jun 20, 2012

need http redirect and then pool selection based on local port

irule noob here... but i'll describe what i'm trying to accomplish followed by my weak attempt at solving it through an irule...

 

 

-a user goes to http://page.example.com

 

-they get redirected to https://page.example.com/URI_Path and use pool1

 

 

 

however, one of the applets within https://page.example.com/URI_Path sends the user a redirect with a location of: http://page2.example.com:8003/newURI_Path. This applet is served off a different node/member listening on port 8003.

 

 

 

so my solution was to create an iRule as follows:

 

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] equals "/" } {

 

HTTP::redirect "https://page.example.com/URI_Path"

 

pool pool1

 

}

 

if { [TCP::local_port] equals 8003} {

 

HTTP::redirect "https://page.example.com/newURI_Path"

 

pool pool2

 

}

 

}

 

 

 

 

Where pool2 is the backend server listening on port 8003.

 

 

 

I'm sure there's a cleaner way to do this and I'd love any better ideas... But for now, I can't even get the 1st portion of the irule to work. I get the redirect, but it never goes to the pool. Note that I do not have any default pool set in my HTTPS virtual server.

 

 

 

Thanks

 

3 Replies

  • You can't set a redirect AND send traffic to a pool, they are mutually exclusive.

     

     

    Perhaps you wanted to actually rewrite the path rather than having the client redirect to it? If so, you can use HTTP::uri instead of HTTP::redirect to do this.

     

  • Thanks for the response but I'm still having trouble... The goal is this... Initially, yes, we want to append a path to a hostname...

     

     

    So when users come to somewhere.domain.com, I want to send them to somewhere.domain.com/here and I want them to use poolA

     

     

     

    While the users are navigating around somewhere.domain.com/here, they may click on an applet that sends them a redirect to a different backend server which I've configured as a separate pool member (poolB)... So my thinking was, when the client receives this redirect, my iRule would send them to poolB.

     

     

     

    Here's what my iRule looks like now and it's not working...

     

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::uri] contains "configurator" } {

     

    pool poolB

     

    }

     

    elseif { [HTTP::uri] equals "/" } {

     

    HTTP::uri "/QITF/faces/portal"

     

    pool poolA

     

    }

     

    }

     

     

     

     

    The redirect the client receives is something to the effect of somewhere.domain.com:8003/configurator. I was thinking of either using "URI contains" or "TCP local port equals"

     

     

     

    And I do not have a default pool set up on this VS.

     

     

     

     

     

  • You will probably want to add a default case to the iRule else you risk dropping requests for URIs which don't contain configurator or are exactly /. You can also use a switch statement to check the URI.

    I don't understand the exact scenario, but you should be able to figure out more about what's happening by adding logging and using a browser plugin that lets you check the requests the client sends and the responses it receives.

    
    when HTTP_REQUEST {
    
    log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri]"
    switch -glob [HTTP::uri] {
    "*configurator*" {
    pool poolB
    log local0. "[IP::client_addr]:[TCP::client_port]: Matched configurator, selecting poolB"
    }
    "/" {
    HTTP::uri "/QITF/faces/portal"
    pool poolA
    log local0. "[IP::client_addr]:[TCP::client_port]: Matched /, selecting poolA"
    }
    default {
    pool poolX
    log local0. "[IP::client_addr]:[TCP::client_port]: Matched default, selecting poolX"
    }
    }
    }
    when HTTP_RESPONSE {
    log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::status] from [LB::server] (redirect? [HTTP::header Location])"
    }
    

    What is Fiddler? Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet

    www.fiddler2.com/

    Aaron