Redirect to other url

Community Forum Forums Thunder and AX Series Redirect to other url

This topic contains 10 replies, has 3 voices, and was last updated by avatar diederik 2 months, 3 weeks ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #15672
    avatar
    gundam
    Member

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

    #15682
    avatar
    diederik
    Member

    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

    • This reply was modified 3 months ago by avatar diederik.
    • This reply was modified 3 months ago by avatar diederik.
    #15722
    avatar
    gundam
    Member

    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

    #15752
    avatar
    diederik
    Member

    Yes that should work. Make sufre the " " are the correct ones though.
    See the difference in your post and mine.

    • This reply was modified 2 months, 4 weeks ago by avatar diederik.
    #15812
    avatar
    gundam
    Member

    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

    #15822
    avatar
    diederik
    Member

    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.”.

    • This reply was modified 2 months, 4 weeks ago by avatar diederik.
    #15842
    avatar
    gundam
    Member

    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

    #15852
    avatar
    diederik
    Member

    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 {

    • This reply was modified 2 months, 3 weeks ago by avatar diederik.
    #15872
    avatar
    ericn
    Member

    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.

    #15902
    avatar
    gundam
    Member

    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

    • This reply was modified 2 months, 3 weeks ago by avatar gundam.
    #15922
    avatar
    diederik
    Member

    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"
         }
    }
    
    • This reply was modified 2 months, 3 weeks ago by avatar diederik.
Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

Comments are closed.