Forum Discussion

bob_rao_7722's avatar
bob_rao_7722
Historic F5 Account
Apr 04, 2006

host header

I have a server that is listening as a web server on a virtual host. So when I go to my web browser and type: "images.testme.com" I go to the web site I created on that server. I have two servers set up like this.

 

Now I want to front end this with a bigip and use a VIP – but I can not seem to get the host name insert part working using irules I have written.

 

 

What iRule command would I use to insert this host name?

 

I assume it is:

 

HTTP::header insert

 

 

bob

6 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Well, depending on what it is you're actually trying to do, then yes, you could use the HTTP::header insert command.

    If you're trying to add a custom header, then you'd do something like:

    
    when HTTP_REQUEST { 
      HTTP::header insert X-yourcustomheader "value"
    }

    I'm not quite clear on what it is you're trying to do though.

    I understand you have two vitual hosts running seperate webservers. And now you're putting a BIG-IP in front of them. What is it you want the BIG-IP to do?

    -Colin
  • bob_rao_7722's avatar
    bob_rao_7722
    Historic F5 Account

     

    Send traffic to the 2 virtual hosts.

     

    This way we can load balance to the 2 virtual hosts.

     

     

    bob
  • bob_rao_7722's avatar
    bob_rao_7722
    Historic F5 Account
    The servers listen for the web site – using host headers.

     

    So when I want to go to the default web page on the server – I type “images.dev.testme.com”. This will bring me to the default page for this web site. This web server has 12 different web sites listening on the same ip address. In order to distingue between the different sites, they are using host headers.

     

    Now they want to put “images.dev.testme.com” on two servers - and load balance between them.

     

    So the customer wants to front end this site with a bigip. So when the customer types the “VS”’s IP address – they will be load balanced to the web server instances on the server.

     

    So the clients do not - and will not know the host name. Just the VS's ip address.

     

     

    bob
  • Just use the HTTP::header replace command to replace the "Host" header value.

    when HTTP_REQUEST {
      HTTP::header replace "Host" "images.dev.testme.com"
    }

    This will replace the current "Host" header consisting of the IP address in the requested url with "images.dev.testme.com".

    -Joe
  • class myIPRelations {

     

    "192.168.30.119 images.test.com"

     

    }

     

     

    when HTTP_REQUEST {

     

    set newHost [findclass [IP::remote_addr] $::myIPRelations " "]

     

    if { [string length $newHost] > 1 } {

     

    HTTP::header replace Host $newHost

     

    }

     

    }

     

     

     

    The above rule does not seem to work.

     

    When we go threw the bigip we see the following result when we run a tcp dump from the server.

     

     

    GET /parts/img/bcl/bc23220.jpg HTTP/1.1

     

     

    Host: images.test.com

     

     

    User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.1) Gecko/20060313 Fedora/1.5.0.1-9 Firefox/1.5.0.1 pango-text

     

     

    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

     

     

    Accept-Language: en-us,en;q=0.5

     

     

    Accept-Encoding: gzip,deflate

     

     

    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

     

     

    Keep-Alive: 300

     

     

    Connection: keep-alive

     

     

    Cache-Control: max-age=0

     

     

    Now when we go to the server directly it works- this is what we see.

     

    this is from a tcpdump on the server again. Notice we do not see the "referer" in the capture above

     

     

    GET /parts/img/acd/10072.jpg HTTP/1.1

     

     

    Host: images.dev.test.com

     

     

    User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.1) Gecko/20060313 Fedora/1.5.0.1-9 Firefox/1.5.0.1 pango-text

     

     

    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

     

     

    Accept-Language: en-us,en;q=0.5

     

     

    Accept-Encoding: gzip,deflate

     

     

    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

     

     

    Keep-Alive: 300

     

     

    Connection: keep-alive

     

     

    Referer: http://images.dev.test.com/parts/img/acd/

     

     

    If-Modified-Since: Wed, 15 Mar 2006 14:40:49 GMT

     

     

    If-None-Match: "3ace1-4c32-44182771"

     

     

    Cache-Control: max-age=0
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    Let me try to re-state the problem description as I understand it:

    1) You have several sites available on 2 or more servers for load balancing. The servers are virtual hosts on the same server answering to the same IP address.

    2) The server in your example is configured to serve a virtual site named "images.dev.test.com". (Successful GET uses that Host: header.) Several other virtual hosts are configured on the same IP address. For demonstration purposes, let's say that the other hostnames are "site1.dev.test.com" and "site2.dev.test.com"

    3) You'd like users to be able to browse to the various sites by typing "http://images.test.com", "http://site1.test.com", "http://site2.test.com".

    4) I'm assuming all these names are pointing to the same virutal server address to which this rule will be applied.

    -- straighten me out if I got any of that wrong --

    To solve this problem, most customers simply configure the virutal hosts on each webserver with the hostnames the end users will actually use, i.e. "images.test.com". That is the simplest solution, and requires no iRule header translation.

    If for some reason the backend hosts /must/ use different hostnames than the BIG-IP virtual server, this rule will translate the inbound host header to that expected by the webserver:

    class hostTranslations {
      "images.test.com images.dev.test.com"
      "site1.test.com site1.dev.test.com"
      "site2.test.com site2.dev.test.com"
    }
    rule hostTranslations_with_lookup {
    when HTTP_REQUEST {
      set newHost [findclass [HTTP::host] $::hostTranslations " "]
        if { [info exists $newHost] } {
          HTTP::header replace Host $newHost
        }
    }
    }

    Or if the naming scheme is consistent enough that you can just always remove the subdomain name, you can use this without having to configure a class:

    rule hostTranslations_simpler {
    when HTTP_REQUEST {
      HTTP::header replace Host [getfield [HTTP::host] "." 1].[getfield [HTTP::host] "." 3].[getfield [HTTP::host] "." 4]
    }
    }

    Post a follow up if I didn't get the problem description correct, and I should be able to help further.

    /deb