Forum Discussion

ukitsysadmin_95's avatar
ukitsysadmin_95
Icon for Nimbostratus rankNimbostratus
Mar 19, 2010

HTTP rewrite to specified nodes

Hello all,

 

 

Does anyone know how to write an irule for redirecting http requests to nodes in a pool.

 

 

I have a web farm of 10 servers all serving the same content, but I want a way to monitor each node is serving web pages correctly

 

currently, I have to change my host file 10 times to check each host is working

 

 

I tried to get this irule working without any success

 

 

what this should do, is if I type www.abc.com/node1 it should remove the /node1 and redirect www.abc.com onto server 1.1.1.72

 

 

when HTTP_REQUEST {

 

 

switch -glob [HTTP::path] {

 

 

/node1 {

 

Remove the /node1 prefix from the path

 

HTTP::path [string map -nocase {/node1 ""} [HTTP::path]]

 

 

Set the node

 

node 1.1.1.72 80

 

}

 

 

/node2 {

 

Remove the /node1/ prefix from the path

 

HTTP::path [string map -nocase {/node2 ""} [HTTP::path]]

 

 

Set the node

 

node 1.1.1.75 80

 

}

 

 

/node3 {

 

Remove the /node1/ prefix from the path

 

HTTP::path [string map -nocase {/node3 ""} [HTTP::path]]

 

 

Set the node

 

node 1.1.1.76 80

 

}

 

 

/node4 {

 

Remove the /node1/ prefix from the path

 

HTTP::path [string map -nocase {/node4 ""} [HTTP::path]]

 

 

Set the node

 

node 1.1.1.77 80

 

}

 

 

/node5 {

 

Remove the /node1/ prefix from the path

 

HTTP::path [string map -nocase {/node5 ""} [HTTP::path]]

 

 

Set the node

 

node 1.1.1.78 80

 

}

 

 

default {

 

Take some default action?

 

pool My_pool_80

 

}

 

 

}

 

}

 

 

 

also is there a way of logging, when someone enters www.abc.com/host1, it redirects to the correct node listed above

 

 

 

thanks in advance

1 Reply

  • Hi Mr Sysadmin,

     

     

    I think the problem might be that you're rewriting the URI to nothing. Can you change your rewrites to:

     

     

    HTTP::path [string map -nocase {/nodeX "/"} [HTTP::path]]

     

     

    Also, if you want another option that supports pinning the request to the server for the duration of the session, you can try this Codeshare example:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/Select_pool_member_based_on_HTTP_query_string_parameter.html

     

     

    Aaron