Forum Discussion

Michael_60521's avatar
Michael_60521
Icon for Nimbostratus rankNimbostratus
Feb 12, 2013

Redirect TCP connection based on hostname

hi.

I am trying to redirect a connection based on the hostname that the request came in.

I have a VS on tcpport 5222 (special programe made for us) It is not http, so I cannot use this :

when HTTP_REQUEST {
       if {[HTTP::host] eq "1.domain.com" } {
        node 10.20.61.21:5222
     } elseif {[HTTP::host] eq "2.domain.com" } {
        node 10.21.61.21:5222
     } elseif {[HTTP::host] eq "3.domain.com" } {
        node 10.22.61.21:5222
     } elseif {[HTTP::host] eq "4.domain.com" } {
        node 10.23.61.21:5222
     } elseif {[HTTP::host] eq "5.domain.com" } {
        node 10.24.61.21:5222
     } elseif {[HTTP::host] eq "6.domain.com" } {
        node 10.25.61.21:5222
     } else {
        HTTP::redirect "https://domain.com"
  }
}

If I use the above, it will redirect to https://domain.com ...

what to use insted of HTTP::host ?? to catch the tcp-port 5222 and send it to the right node ??

Michael

2 Replies

  • eey0re's avatar
    eey0re
    Icon for Cirrostratus rankCirrostratus

    To expand on nitass' answer a little.. you can't do what you're after if it's not HTTP, unless there is something in the TCP payload that you can parse. You'd do that using TCP::collect, and it could get tricky.

     

    An HTTP server only knows what hostname a client used to arrive because the client sends it as an HTTP header. With plain TCP, there is no way to tell.

     

    Secondly, you say you want to "redirect" the client. You can't do that with plain TCP either. HTTP::redirect works by sending an HTTP response telling the client to go to another URL. With plain TCP, there is no way to "redirect" the client. (You could, however, use TCP::collect to make a load balancing decision - e.g. select a different pool.)