Contribute Open Script

HTTP Redirects

by Derek_Kang on ‎11-13-2012 03:39 PM (88 Views)
Tested with Brocade ServerIron ADX

Yes with 12.4.00c

Description

For this use case, the ADX is assumed to have an SLB VIP listening on port 80 (HTTP) and port 443 (HTTPS) associated with the same set of real servers; hence, HTTPS(SSL) traffic is terminated on the ADX and only HTTP is used between the ADX and real servers. The communication between a client and the VIP must be secure, meaning the web contents must be carried over HTTPS. So, when a client tries to access the VIP via HTTP, the ADX redirects the client to HTTPS. If all of the servers are down, the ADX redirects the client to a sorry server, "sorry.xxx.com/sorry.htm"

Limitations

None; just note that you have to list up your servers and server IDs in the hash table in the BEGIN subroutine.

Required Environment

A global command ,“server l7-dont-reset-on-vip-port-fail”,  must be configured on the ADX unit. In this script, it is assumed that you have two virtual ports in the same VIP, port 80 and port 443. The script is attached to the port 80 of the VIP.

Code

use strict;

use OS_SLB;

use OS_HTTP_REQUEST;

my %rs_list;

sub BEGIN {

  %rs_list = (1030=>"rs1", 1031=>"rs2", 1032=>"rs3"); #list up your real servers with server ID

}

sub HTTP_REQUEST {

  my $domain = OS_HTTP_REQUEST::host;

  my $url = OS_HTTP_REQUEST::url;

  my $any_server_up = 0;

  foreach my $server_id (keys %rs_list) {

      if (OS_SLB::up($rs_list{$server_id}, 80) == 1) {

          $any_server_up = 1;

          last;

      }

   }

   if ($any_server_up == 1) {

      OS_SLB::redirect("domain"=>$domain, "url"=>$url, "port"=>"443");

   } else {

      OS_SLB::redirect("domain"=>"sorry.xxx.com" , "url"=>"/sorry.htm" , "port"=> "80" );

   }

}