Forum Discussion

Parveez_70209's avatar
Parveez_70209
Icon for Nimbostratus rankNimbostratus
Oct 17, 2013

How to switch between the pools based on the listening port into the Irule

How to switch between the pools based on the listening port using irule

 

  1. Whenever HTTP_Request hits with listening port 8080, it will switch to Poola and whenever HTTP_Request hits with listening port 1099, it shoukd go to pool : Poolb

Thanks and Regards Parveez

 

4 Replies

  • A simple example:

    when CLIENT_ACCEPTED {
        switch [TCP::local_port] {
            "8080" { pool Poola }
            "1099" { pool Poolb }
        }
    }
    

    You could also dump these into a string-based data group. Example:

    8080 := Poola
    1099 := Poolb
    

    And use a more dynamic version of the iRule:

    when CLIENT_ACCEPTED {
        if { [class match [TCP::local_port] equals my_port_dg] } {
            pool [class match -value [TCP::local_port] equals my_port_dg]
        }
    }
    
  • And also Kevin:

     

    By applying the below Irule, also wanted to edit/add this irule saying to redirect it to https when the traffic hit to http.

     

    when CLIENT_ACCEPTED { switch [TCP::local_port] { "8080" { pool Poola } "1099" { pool Poolb } } }

     

    Thanks and Regards Parveez

     

  • Switch to this then:

    when HTTP_REQUEST {
        switch [TCP::local_port] {
            "8080" { pool Poola }
            "1099" { pool Poolb }
            "80" { HTTP::redirect "https://[HTTP::host][HTTP::uri]"
        }
    }