Forum Discussion

Dev_56330's avatar
Dev_56330
Icon for Cirrus rankCirrus
Sep 28, 2016

Select Pool based on URI & run ProxyPass Lite

I currently have a functional iRule to redirect users to a specific pool based on uri though I am looking for assistance running both that iRule and then run proxypass for only one of the uri's. Would it best to use a procedure as both iRules contain HTTP_Request events or priority iRules? Or is there a more simple way? Can this even be done with an if else statement and would that have to be applied on HTTP request and response?

 

5 Replies

  • Basically I am trying to combine the two iRules below and only running the second iRule if the uri matches /vra.

    when HTTP_REQUEST { 
        switch -glob [string tolower [HTTP::path] ] {
            "/vra*" { pool VRA 
                log local0. "User directed to VRA" } 
            "/vdi*" { pool VDI 
                log local0. "User directed to EXT" } 
            default { pool somefallbackpool 
                log local0. "User directed to Fallback pool" } 
        } 
    }
    
    when RULE_INIT {
    
        Log debug messages to /var/log/ltm? 1=yes, 0=no
       set static::rewrite_debug 1
    
        External hostname for the web application
       set static::external "externalwebpage.com"
    
        Internal hostname for the web application
       set static::internal "internalwebpage.com"
    }
    when HTTP_REQUEST {
    
       if {$static::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: New HTTP request to [HTTP::host][HTTP::uri]"}
    
        Prevent the server from sending compressed responses as LTM does not decompress them
       HTTP::header remove "Accept-Encoding"
       if {$static::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Removing Accept-Encoding request header"}
    
        Replace host header with the internal name
       HTTP::header replace Host $static::internal
    
        Disable the stream filter for non-text responses
       STREAM::disable
    }
    when HTTP_RESPONSE {
    
        Rewrite Location header value in HTTP redirects if it contains the $static::internal string
       if {[HTTP::is_redirect] && [string tolower [HTTP::header "Location"]] contains $static::internal}{
    
           Replace $static::internal with $static::external in Location header value
          HTTP::header replace Location [string map "$static::internal $static::external" [HTTP::header Location]]
    
          if {$static::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Updated location from [HTTP::header Location]\
             to [string map "$static::internal $static::external" [HTTP::header Location]]"}
       }
    
        Rewrite the response body if the response type is text
       if { [HTTP::header "Content-Type"] starts_with "text/" } {
    
           Configure the find/replace strings
          STREAM::expression "@$static::internal@$static::external@"
    
           Enable the stream filter
          STREAM::enable
    
          if {$static::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Enabled stream filter for $static::internal -> $static::external"}
       }
    }
    
  • In the proxypass datagroup, ONLY define the URI you want to be processed by ProxyPass. All other requests will only run through the first iRule.

     

    • Dev_56330's avatar
      Dev_56330
      Icon for Cirrus rankCirrus

      If this were any iRule other than proxypass lite but I only wanted to execute it if the uri was /vra can someone assist me is modifying an iRule to do so? This is all using a single Virtual Server with a pool for VDI and a pool for VRA.

       

  • In the proxypass datagroup, ONLY define the URI you want to be processed by ProxyPass. All other requests will only run through the first iRule.

     

    • Dev_56330's avatar
      Dev_56330
      Icon for Cirrus rankCirrus

      If this were any iRule other than proxypass lite but I only wanted to execute it if the uri was /vra can someone assist me is modifying an iRule to do so? This is all using a single Virtual Server with a pool for VDI and a pool for VRA.