Forum Discussion

Moreli_Alama_63's avatar
Moreli_Alama_63
Icon for Nimbostratus rankNimbostratus
May 14, 2007

irule for 503 response to client

hi

 

 

i have a http VIP and am wanting to create a 503 response to the client

 

when the VIP is unavailable. how does one achieve this? i can see you can assign

 

monitors to pools but nothing jumps about how an irule or action is invoked

 

when the http monitor is down.

 

 

your help appreciated.

 

 

m

4 Replies

  • To issue a redirect when the pool is down, specify a Fallback Host in the HTTP profile.

     

     

    I have just uploaded an iRule that improves on this behavior, because the Fallback Host behavior is not ideal. See http://devcentral.f5.com/wiki/default.aspx/iRules/Webserver_Down_Message.html

     

     

    As I point out on that page, though, 503 is the magic status code that makes the code fail. Can anyone shed some light on this bug?
  • +1 : it seems that a public web site must return a 503 error page instead of a 302 (as the BigIP does), because 302 are followed by bots, which means that a maintenance period can ruin some rankings.

     

     

    Has anyone made some progress on how to force BigIP redirect using 503 response code ?

     

     

    Tx.
  • In a simple test on 9.4.6, I was able to send a 503 with content using HTTP::respond. I've also used a 503 in 9.2.4 and 9.3.1. I'm not sure if it was a bug in an older version or a configuration issue. But if you're seeing a problem with sending a 503, can you post the iRule you're testing and the results of the tests?

     

     

     
     when HTTP_REQUEST { 
      
        set data {Some data to send to the client.  If you want to use variables in here, replace the curly braces with quotes.} 
      
         Look for a URI starting with a forward slash and then 3 digits (the first digit being 1-5) 
         If one is found, set it as the HTTP response code.  Else, send back an HTTP 200 
        if {[string match {/[1-5][0-9][0-9]*} [HTTP::path]]}{ 
      
            Send the response with the status code from the requested path and data 
           HTTP::respond [string range [HTTP::path] 1 3] content $data "a_header_name" "a_header_value" 
           log local0. "Sending [string range [HTTP::path] 1 3] response with $data" 
        } else { 
            Send a 200 response with data 
           HTTP::respond 200 content $data "a_header_name" "a_header_value" 
           log local0. "Sending default 200 response with $data" 
        } 
     } 
     

     

     

    Example curl request:

     

     

     

    curl -v 10.42.2.102/503

     

    * About to connect() to 10.42.2.102 port 80

     

    * Trying 10.42.2.102... connected

     

    * Connected to 10.42.2.102 (10.42.2.102) port 80

     

    > GET /503 HTTP/1.1

     

    > User-Agent: curl/7.15.3 (i686-redhat-linux-gnu) libcurl/7.15.3 OpenSSL/0.9.7l zlib/1.1.4

     

    > Host: 10.42.2.102

     

    > Accept: */*

     

    >

     

    < HTTP/1.0 503 Service Unavailable

     

    < a_header_name: a_header_value

     

    * HTTP/1.0 connection set to keep alive!

     

    < Connection: Keep-Alive

     

    < Content-Length: 109

     

    Connection 0 to host 10.42.2.102 left intact

     

    * Closing connection 0

     

    Some data to send to the client. If you want to use variables in here, replace the curly braces with quotes.

     

     

     

     

    Aaron
  • Tx for the quick reply. In the mean time, we managed to have the fallback host respond with a 503 code, which would solve the mentioned problem (plus an additional in the HTML code). Nevertheless, I keep a bookmark on this iRule, and I'll let you know if/when I need to put it in place.