Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Redirecting to an external site when the internal site is down

John_Adams
Nimbostratus
Nimbostratus

Hi, folks,

     I've read several articles with iRules for redirection and think I understand that part of my problem, but I've seen nothing about how to trigger the redirection when the local site is down, which is what I'm being asked to do.

Thanks,

     John A

1 ACCEPTED SOLUTION

@John_Adams It seems like we cannot use a variable that has been created in that section of code. You can try the following to see if this works for you.

when HTTP_REQUEST priority 500 {

    if { [active_members [LB::server pool]] == 0 } {
        HTTP::respond 307 content {
            <html>
            <head>
            <title>Apology Page</title>
            </head>
            <body>
            We are sorry, but the site you are looking for is temporarily out of service<br>
            If you feel you have reached this page in error, please try again.
            </body>
            </html>
        }
    }

}

View solution in original post

7 REPLIES 7

Hi,

It's more than doable by irule and i'm sure in a built policy.
But how about these references for a start
https://my.f5.com/manage/s/article/K6510
https://www.youtube.com/watch?v=r-GndW4H3ck
https://www.youtube.com/watch?v=nJLK8G7eqbU

I've not looked at the youtube video's just search for them, but the f5 kb looks close to what you are looking for.
A policy may also be a quick fix to - i can find that method out to if you're not wanting to go down the irule route.

 

 

Hi,

     I see that first video shows the use of HTTP::respond instead of HTTP::fallback! That's perfect, because the request is to return a 307, and it appears HTTP::fallback only returns a 302.

Thanks,

     John A

@John_Adams Typically this is achieved by using two pieces of configuration together.

1. The pool associated to the virtual server in question will have a health monitor for that site and if the response from the pool members is something other than what you define in the receive string then the pool member/s is/are considered down making the entire virtual server go down if the entire pool is down.
2. When the pool is completely down or the iRule defined criteria is met, such as less than 2 pool members of the over all pool members are available then you issue the redirect otherwise you just forward traffic to the pool and let load balancing occur.

The following is an example iRule of how to perform this function with an example website. If you needed to narrow this down to a specific site and associate pool you could add in the additional matching criteria.

 

when CLIENT_ACCEPTED {

    set DEFAULT_POOL [LB::server pool]

}

when HTTP_REQUEST {

    if { [active_members [${DEFAULT_POOL}]] == 0 } {
        HTTP::respond 307 Temporary Redirect "http://www.example.com/"
    }

}

 

 

Hi, @Paulius,

     I've tried to implement this more or less as is:

when CLIENT_ACCEPTED {

             set DEFAULT_POOL [LB::server pool]

}

when HTTP_REQUEST {

          if { [active_members [${DEFAULT_POOL}]] == 0 } {
                   HTTP::respond 307 content {
<html>
<head>
<title>Apology Page</title>
</head>
<body>
We are sorry, but the site you are looking for is temporarily out of service<br>
If you feel you have reached this page in error, please try again.
</body>
</html>
                   }
          }

}

and I am getting an interesting error:

tmm1[12440]: 01220001:3: TCL error: /Common/_ualr_hostdown_307 <HTTP_REQUEST> - invalid command name "/Common/<app name>/<pool name>"     while executing "${DEFAULT_POOL}"

     I'm also getting it when I switch to the "Temporary Redirect <URL>" code you presented. Any thoughts?

Thanks,

     John A

@John_Adams It seems like we cannot use a variable that has been created in that section of code. You can try the following to see if this works for you.

when HTTP_REQUEST priority 500 {

    if { [active_members [LB::server pool]] == 0 } {
        HTTP::respond 307 content {
            <html>
            <head>
            <title>Apology Page</title>
            </head>
            <body>
            We are sorry, but the site you are looking for is temporarily out of service<br>
            If you feel you have reached this page in error, please try again.
            </body>
            </html>
        }
    }

}

@Paulius, I'm now getting no errors and the apology text in Safari, Firefox, and Chrome, which is clear progress and fulfills my specific task.

One oddity: When I tried the "Temporary Redirect <URL>" code you offered, I get no errors and blank screens with all browsers. It's throwing up that apology message that I've been asked to do, but I'm still curious about the other syntax and why it's not working. It seems very straightforward and I don't believe I have any typos.

@John_Adams My mistake on this one. Because you're wanting the F5 to serve a generic website you should do the following instead of a 307. You would use the redirect if you were sending a new URL to the client but in this case you are sending a basic website.

when HTTP_REQUEST priority 500 {

    if { [active_members [LB::server pool]] == 0 } {
        HTTP::respond 200 content {
            <html>
            <head>
            <title>Apology Page</title>
            </head>
            <body>
            We are sorry, but the site you are looking for is temporarily out of service<br>
            If you feel you have reached this page in error, please try again.
            </body>
            </html>
        }
    }

}