Forum Discussion

ccmoore's avatar
ccmoore
Icon for Nimbostratus rankNimbostratus
Apr 14, 2023

f5 reverse proxy to remove ports in URI

Hello,

I have to containers running on an internal docker host. Two apps presenting on two ports. 9445 and 42828.

I have one domain testws02.usneeded.com.

to hit the containers now we have to go to testws02.usneeded.com:9445 or testws02.usneeded.com:42828

I need to be able to go to testws02.usneeded.com/v9/ or testws02.usneeded.com/v10/ (not sure if the last / is required).

I've attempted to use the rewrite profile feature in f5 ltm 12.1.5 however it seems to only work for one of them the other isnt working. 

How would you guys do this?

5 Replies

  • You could try using a local traffic policy:

    testws02.usneeded.com/v9   =>  testws02.usneeded.com:9445
    testws02.usneeded.com/v10  =>  testws02.usneeded.com:42828

    Replace <NODE IP> with the actual IP of the back-end server.
    create ltm policy Drafts/POLICY-REWRITE-TESTWS02.USNEEDED.COM strategy all-match rules add { v9 { ordinal 0 conditions add { 0 { http-host host equals values { testws02.usneeded.com } } 1 { http-uri path starts-with values { /v9 } } } actions add { 0 { http-uri replace value / } 1 { forward select node <NODE IP>:9445 } } } v10 { ordinal 1 conditions add { 0 { http-host host equals values { testws02.usneeded.com } } 1 { http-uri path starts-with values { /v10 } } } actions add { 0 { http-uri replace value / } 1 { forward select node <NODE IP>:42828 } } } }
    
    publish ltm policy Drafts/POLICY-REWRITE-TESTWS02.USNEEDED.COM
    
    modify ltm virtual <VS NAME> policies add { POLICY-REWRITE-TESTWS02.USNEEDED.COM }

     

  • Client traffic comes on port :XXXXX already or is it HTTP(s) on standard port with the /vXX uri ? 
    Do you backend server require the GET request to have the port specified? 

    If you have only one virtual server, I'd configure two pools - one for port 42828 and one for port 9445 - and use a simple iRule (something like the following) to route traffic accordingly

     

     

    when HTTP_REQUEST {
      if {[string tolower [HTTP::host]] ne "testws02.usneeded.com"}{ return }
      switch -regex [HTTP::uri] {
        ^\/v9\/   { pool p_testws02_9445 }
        ^\/v10\/  { pool p_testws02_42828 }
        default   { pool p_testws02_http }
      }
    }

     

     

     

    • ccmoore's avatar
      ccmoore
      Icon for Nimbostratus rankNimbostratus

      What pool is the default pool then? Do you mean have 3 pools?

      • CA_Valli's avatar
        CA_Valli
        Icon for MVP rankMVP

        You should specify a default staetment that matches connections that don't meet previous criteria, 

        action can be anything you want - you can load balance it or you can drop it if that's the best option for you.