Forum Discussion

Striker_88408's avatar
Striker_88408
Icon for Nimbostratus rankNimbostratus
Aug 28, 2007

I'm new to iRules, i'm looking for a iRules who can can return an URI from a VIP

Hi every1 of the forum,

 

 

I'm new to iRules, so all help with this would be really appreciate.

 

 

I need to configure a iRules that can return an URI when i call the VIP adress. Do you have an idea of how to do that ?

 

 

Thank you in advance,

7 Replies

  • If you want an iRule that sends a canned HTTP response, you can use the HTTP::respond command (Click here).

    Here is an example:

    
    when HTTP_REQUEST {
       HTTP::respond 200 "some html content"
    }

    If you want to send a 302 redirect, you can use:

    
    when HTTP_REQUEST {
       HTTP::redirect http://somehost.example.com
    }

    If this isn't what you're looking for, can you elaborate?

    Thanks,

    Aaron
  • Hmm ok ill try to explain a more what i'm looking for.

     

     

    Here an exemple:

     

    Pool test1 contain 2 servers:

     

    -10.x.y.1 --> URI :server1

     

    -10.x.y.2 --> URI :server2

     

     

     

    You have a client machine with a google window open. That machine is asking for 10.x.y.z(virtual server).

     

     

    The Big-Ip will decide on witch server he will direct the HTTP request.

     

     

    I want that the return to the client be the URI of that server, but not its IP.

     

     

    Hope it will help, Thank you
  • When a client makes a request for the VIP, 10.x.y.z, BIG-IP selects a node to send the request to. By default, the BIG-IP doesn't change the node's response headers or data. The node might be sending a redirect to the node's IP address. Or the node might be inserting a hardcoded reference to it's own IP address in the HTTP content.

     

     

    From your description, it sounds like the node is sending a redirect back to the client and in that redirect, the Location field contains the node's IP address.

     

     

    Does this sound accurate? If so, is the VIP configured for HTTP or HTTPS (or do you have a pair of VIPs for HTTP and HTTPS)?

     

     

    Aaron
  • Hello again,

     

     

    First the VIP is a HTTP one, with a pool of 2 nodes.

     

     

    When the client ask for the VIP, the first or second node respond. It respond well, no problem there.

     

     

    But when the node respond, the VIP adresse still rest in the URL bar. I wish it could be the URI of the node that answer.

     

     

    Thank you,
  • Can you try this example to rewrite the Location header value to the fully qualified domain name that resolves to the VIP and see if this is what you're trying to achieve?

    
    when HTTP_RESPONSE {
       
       if {[HTTP::is_redirect]}{
          set virtual_ip [clientside {IP::local_addr}]
          set domain_name "host.example.com"
          set location [HTTP::header value Location]
          HTTP::header replace Location [string map [list $virtual_ip $domain_name] $location]
          log local0. "Updated Location header: [HTTP::header value Location]"
       }
    }

    If that works, then you can use a version with less variables and no logging:

    
    when HTTP_RESPONSE {
       if {[HTTP::is_redirect]}{
          set domain_name "host.example.com"
          HTTP::header replace Location [string map [list [clientside {IP::local_addr}] $domain_name] [HTTP::header value Location]]
       }
    }

    Aaron
  • Actually... I just reread what you wrote and I think I misinterpreted it.

     

     

    Does the client click on a link or manually type in the resource to access the virtual server? Is this the virtual IP or a host name that resolves to the VIP address?

     

     

    Once a load balancing decision has been made, do you then want to have the client access the virtual server by an alias for the node? Or are you wanting the client to then access that node directly (not going through the BIG-IP)?

     

     

    I'm still a bit confused on what you want to happen.

     

     

    Aaron
  • Hello Aaron,

     

     

    Thnak you for all the suggestions, i've retalk with my client, he only wanted a way to test iRules on VIP.

     

     

    He just gave me this exemple:

     

    when HTTP_REQUEST {

     

     

    if { ( [HTTP::method ] equals "GET") } {

     

     

    if { ( [HTTP::uri ] equals "/xyz") } {

     

     

     

    HTTP::respond 200 content "

     

     

    HTTP Status Code Report

     

     

     

     

    WRONG PAGE – Buddy – Try next time "

     

    }

     

    }

     

    }

     

     

    It's ok now i made it work well, sry if it was confusing at the beginning.