Forum Discussion

phipse's avatar
phipse
Icon for Altostratus rankAltostratus
Mar 03, 2019

LTM iRule Reverse Proxy redirect

Hi Guys,

Sorry for the repeat post in advance. I'm trying to configure a reverse proxy (RP) using an iRule, but I can not get it to work. I'm a network engineer by trade, but I love learning this BIG-IP stuff.

I have a URL with the following requirements:

http://10.20.10.10:4400/ucit/downloaddocument

should be sent to

http://192.168.8.101:8040/services/downloaddocument

Anything that doesn't match the url should be sent to pool_RTS_4400

At the moment 192.168.8.101:8040 is a pool member (pool_Node4RP_Reg) with one server in it.

My application guys say they should be able to view documents via the RP without going direct. So:

Direct: http://192.168.8.101:8040/services/downloaddocument?uuid=829eb8e1-e2a2-4874-b7e6-d20ef4e44bcf

Proxy: http://10.20.10.10:4400/ucit/downloaddocument?uuid=829eb8e1-e2a2-4874-b7e6-d20ef4e44bcf

iRule
when HTTP_REQUEST {
    switch -glob [HTTP::uri] {
        "/ucit/downloaddocument?_wadl" {
        HTTP::uri "/services/downloaddocument?_wadl"
        pool pool_Node4RP_Reg
        log local0. "Node4RP_Reg wad selected [HTTP::path]"
         }
        "/ucit/downloaddocument*" {
        HTTP::uri "/services/downloaddocument*"
        pool pool_Node4RP_Reg
        log local0. "Node4RP_Reg doc* selected [HTTP::path]"
         }
         "/*" {
        pool pool_RTS_4400
        log local0. "Default RTS pool selected [HTTP::path]"
         }
         }
}
  • Phipse,

    Have you tried using string map,

    when HTTP_REQUEST {
       if { [string tolower [HTTP::uri]] starts_with "/ucit" } {
          HTTP::uri [string map {"/ucit/" "/services/"} [HTTP::uri]]
          pool pool_Node4RP_Reg
       } else {
       pool pool_RTS_4400
       }
    }
    
  • Phipse,

    Have you tried using string map,

    when HTTP_REQUEST {
       if { [string tolower [HTTP::uri]] starts_with "/ucit" } {
          HTTP::uri [string map {"/ucit/" "/services/"} [HTTP::uri]]
          pool pool_Node4RP_Reg
       } else {
       pool pool_RTS_4400
       }
    }
    
  • Here's a tip,

    This statement

    HTTP::uri "/services/downloaddocument?_wadl"
    will completely replace your incoming uri to what you have just specified. Thus you'd lose your http queries and it's params.

    Look for how to capture the http query and how to preserve and pass along while changing http uri.

    If you find struggling, pls keep us posted. Happy to help.

  • Is this better?

    
    when HTTP_REQUEST { 
        if { [HTTP::uri -normalized] starts_with "/ucit/downloaddocument?uuid=" } { 
            HTTP::path "/services/downloaddocument?uuid=[HTTP::query]" 
            pool pool_Node4RP_Reg 
        } else { 
            pool pool_RTS_4400
        } 
    }
    
    
  • How do I add the "/services/downloaddocument?_wadl" part into the iRule?

     

    They need to be able to call the wsdl page too?