Forum Discussion

Patrik_146826's avatar
Patrik_146826
Icon for Nimbostratus rankNimbostratus
Nov 18, 2015

Redirect incoming URL to correct port depending on node monitor port

Hi, I'm fairly new with F5 and have a question about iRule or some other way to handle this. The "problem" is as follows: My development team have two servers running the same front end web-application. I have them in a VS and POOL and everything is green in that. But the application is running on different ports on the servers, and they can't be running on the same port (don't ask why). So I want to know if I can use F5 iRule or something to add a port to the incoming URL depending on what port is open on what server?

 

  • Incoming URL: testbeta.example.com/login/test/
  • Health monitor ports: 8081, 8082
  • Pool status:
    • serverA, up, on 8081
    • serverB, up, on 8082
  • Outgoing URL should be: testbeta.example.com:80[81/82]/login/test/

Hopefully someone can help me. I have a hard time searching for this issue. Found nothing yet. Regards, Patrik.

 

5 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    Patrik,

     

    The virtual server configuration will do port translation for you by default, so if the VS is listening on port 80, for example, but your pool members are on 8081 or 8082 then once the pool member is selected the traffic will be sent to the particular port in the pool member configuration - without the need to embed the port in the URL.

     

    Does this help?

     

    N

     

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    Patrik, perhaps an irule is required then to force the host header to include the port. From the DC wiki on LB::select try this, where ServerA ip address is x.x.x.x and ServerB ip is x.x.x.y

    when HTTP_REQUEST {
    
      log local0. "lbserveraddr: [LB::server addr]"
    
       check if serverside connection had previously been established
    
      if { [LB::server addr] eq "" }{
    
         if no serverside connection had previously been established, force one
    
         so the iRule has the info required to insert a destination-specific header
    
        eval [LB::select]
    
      }
    
      switch [LB::server addr] {
    
        "x.x.x.x" { HTTP::header replace Host "[HTTP::host]:8081" }
    
        "x.x.x.y" { HTTP::header replace Host "[HTTP::host]:8082" }
    
      }
    }
    
  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    You wouldn't need switch then (untested irule below):

    when HTTP_REQUEST {
    
      log local0. "lbserveraddr: [LB::server addr]"
    
       check if serverside connection had previously been established
    
      if { [LB::server addr] eq "" }{
    
         if no serverside connection had previously been established, force one
    
         so the iRule has the info required to insert a destination-specific header
    
        eval [LB::select]
    
      }
    
      set port [LB::server port]
    
       HTTP::header replace Host "[HTTP::host]:$port"
    
    }
    
  • After some help from our supplier the following is the solution that worked for me. Pool setup with tcp_half_open as health monitor. Then add each node twice with specific ports, serverA with monitor 8081 and serverA with monitor 8082. This gives 4 members from 2 nodes. And I inherit from the pool. Last I set the VS to port 80 and have an http standard profile enabled and also port translation, also set it to TCP protocol only.

     

    With all this it's now working as we wish.

     

    • nathe's avatar
      nathe
      Icon for Cirrocumulus rankCirrocumulus
      good news Patrik. glad it's working.