Redirect to other url

Can we redirect to external url when all real servers failed health check.

Comments

  • diederikdiederik Member
    edited September 2018
    Yes this is possible using aFlex.

    You can use something like this:
    when HTTP_REQUEST {
       if {[LB::status pool Server_HTTP] == "down" } {
          HTTP::respond 302 Location "https://[HTTP::host][HTTP::uri]"
       }
    }
    



    Use the HTTP response code that suits your requirements best.

    Google & Github are your friend ;)

    https://github.com/a10networks/aflex-collection
    https://www.a10networks.com/resources/articles/aflex-examples
  • gundamgundam Member
    edited September 2018
    Hi diederik

    Thank you for the info and so I can put like this?

    when HTTP_REQUEST {
    if {[LB::status pool Server_HTTP] == "down" } {
    HTTP::respond 302 Location "https://backup.example.com"
    }
    }

    Thank you
  • diederikdiederik Member
    edited September 2018
    Yes that should work. Make sufre the " " are the correct ones though.
    See the difference in your post and mine.
  • gundamgundam Member
    edited September 2018
    Thank you diederik

    How about this case, can I setup redirect for each web site?

    1 VIP 205.222.120.38
    2 real servers web001.com 10.1.1.1 web002.com 10.1.1.2

    hosting multiple web sites on same service-group (server-http)

    https://www.abc.com -> redirect to maintenance.abc.com
    https://www.def.com -> redirect to maintenance.def.com
    https://www.ghi.com -> redirect to maintenance.ghi.com

    Is it possible?

    Thank you
  • diederikdiederik Member
    edited September 2018
    Of course, you could do it something like this:
    when HTTP_REQUEST {
       if {[LB::status pool Server_HTTP] == "down" } {
          set HOST [HTTP::host]
          switch [HTTP::host] {
             www.abc.com  { HTTP::respond 302 Location "maintenance.abc.com" }
             www.def.com  { HTTP::respond 302 Location "maintenance.def.com" }
             www.ghi.com  { HTTP::respond 302 Location "maintenance.ghi.com" }
             default {   log "Unknown HTTP::host $HOST cannot redirect, rejecting connection."
                         reject }
          }
       }
    }
    


    Or like this:
    when HTTP_REQUEST {
       if {[LB::status pool Server_HTTP] == "down" } {
          set HOST [HTTP::host]
          set REDIRECTHOST ""
          switch [HTTP::host] {
             www.abc.com  { set REDIRECTHOST "maintenance.abc.com" }
             www.def.com  { set REDIRECTHOST "maintenance.def.com" }
             www.ghi.com  { set REDIRECTHOST "maintenance.ghi.com" }
             default {   log "Unknown HTTP::host $HOST cannot redirect, rejecting connection."
                         reject }
          }
          HTTP::respond 302 Location "$REDIRECTHOST"
       }
    }
    


    Or you could have the A10 generate the maintenance page for you?
    HTTP::respond 503 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.<p></body></html>"
    


    If you always remove the www and put "maintenance" in front of the hostname you could also look at using regsub to replace "www." in the host with "maintenance.".
  • gundamgundam Member
    edited September 2018
    Thank you diederik

    When I applied this aflex,

    when HTTP_REQUEST {

    if
    {[LB::status pool dlteam-group108_port443] == “down” }

    { HTTP::redirect “http://maintenance.example.com/maintenance.html” }

    }

    This error massage showed up

    Warning: aFleX syntax error: line 3: "wrong # args: no expression after "if" argument"

    dlteam-group108_port443 is service-group name

    Thank you
  • diederikdiederik Member
    edited September 2018
    That is most likely because you quotation marks are wrong.
    Note the difference between:

    if {[LB::status pool Server_HTTP] == "down" } {

    and you version:
    if
    {[LB::status pool dlteam-group108_port443] == “down” }

    You need to use ""
    And you are missing a {
  • ericnericn Member
    edited September 2018
    An easier, and generally more efficient way, to do redirect to URL when the service-group is down (usually because all the servers in that group are down) is to use an HTTP template.
    slb template http MY_HTTP
       . . .
       failover-url http://sorry.example.com
       . . .
    
    slb virtual-server VIP <some.ip.addr>
       port 80 http
          . . .
          template http MY_HTTP
          . . .
    

    The . . . stuff is a stand-in for other needed or desired configuration. In the case of the template http, maybe the only feature you want to use is failover-url, which is fine.

    I have seen the failover-url used in two basic ways (although I am sure there are more)

    1. Lots of vPorts redirect to the same "fail-whale" page somewhere else
    2. There are 2 data-centers, perhaps we're using GSLB, and each location redirects to a specific URL that resolves to another data-center, something like east.www.example.com and west.www.example.com. Of course, there is a bunch more DNS related config to make such a design work.
  • gundamgundam Member
    edited September 2018
    I put "" and got new error.
    when HTTP_REQUEST {
    
         if {[LB::status pool “dlteam-group108_port443”] == “down” } {
    
              HTTP::redirect “http://maintenance.example.com/maintenance.html”
    
         }
    
    }


    Warning: aFleX syntax error: line 3: "syntax error in expression "[LB::status pool “dlteam-group108_port443”]...""

    Thank you
  • diederikdiederik Member
    edited September 2018
    I'm afraid you are still using the wrong quotation marks, and you do not need to put quotation marks around the pool name.

    Do not use word/wordpad or any other word processing tool that wants to intelligently look at your text. You need a plain-text editor or a code-writing tool that does not adjust the quotations to an open and close version.

    The neutral (vertical) quotation mark is used in coding.

    Your code needs to look like this:
    when HTTP_REQUEST {
         if {[LB::status pool dlteam-group108_port443] == "down" } {
              HTTP::redirect "http://maintenance.example.com/maintenance.html"
         }
    }
    
Sign In or Register to comment.