Application delivery script tool in HTTP service

Source: Internet
Author: User

Writing scripts is a key feature in application Delivery Server Load balancer. It is the best embodiment of the flexibility of Server Load balancer policies. Although it may be a "Nightmare" for technical colleagues who do not have the foundation of software development, they feel the same in the face of the "magic" string. For this reason, I have collected some script examples, especially for the optimization of common HTTP traffic, to help you learn from them.

Example 1: automatically convert HTTP requests to HTTPS. This script is relatively simple, but it will be used by many e-commerce websites or customers who access it based on HTTPS.

When HTTP_REQUEST {

HTTP: redirecthttps: // [HTTP: host] [HTTP: uri]

}

Script Description: as long as the Server Load balancer receives the HTTP request packet, it will be converted to HTTPS: // with the domain name and path in the form of HTTP redirection.


Example 2: distribution to the specified server group pool based on the URI path of the client request ). In some customers' business designs, the backend only has one physical server with one IP address and one service port), but different services can be released according to different paths, in this case, the business needs to be differentiated based on the path keyword.

When HTTP_REQUEST {

If {[HTTP: uri] starts_with "/test1 "}{

Pool pool_server1

} Elseif {[HTTP: uri] starts_with "/test2 "}{

Pool pool_server2

} Else }{

Pool pool_server

}

}

Script Description: when the client request path is "/test1", it is allocated to server1. When the client request path is "/test2", it is allocated to server2, all other requests are forwarded to the default server group.


Example 3: automatically select a server cluster in the corresponding country language based on the default language settings of the client browser.

When HTTP_REQUEST {

If {[HTTP: headeraccept-language] contains "es "}{

PoolSpanish

} Elseif {[HTTP: headeraccept-language] contains "ja "}{

PoolJapanese

} Elseif {[HTTP: headeraccept-language] contains "zh "}{

Pool Chinese

} Else {

PoolEnglish

}

}

650) this. width = 650; "src =" http://img1.51cto.com/attachment/201309/215635627.jpg "title =" aflex2.jpg "alt =" 215635627.jpg"/>

Example 4: determine the current number of links of a port service vport on a virtual server. If the threshold value is exceeded, redirect to the specified page !~ It not only protects backend servers, but also provides friendly backup services when receiving abnormal large concurrent connections.

When HTTP_REQUEST {

Set total1 [STATS: get virtual-servervs_192.168.111.45 8080 http current-connection]

If {$ total1> 100 }{

HTTP: redirect "http://www.163.com /"

}

}

Script Description: when the number of concurrent connections to port 8080 of the virtual server 192.168.111.45 exceeds 100, subsequent requests are redirected to other accessible sites, such as www.163.com


Example 5: perform session persistence based on the sessionID of the HTTP packet header. Some websites cannot simply adopt the Source IP Address Session persistence policy. during development, sessionID is used to indicate session information. Through the HTTPwatch tool, we can see that the customer's sessionID is hidden in cookies:

Cookie content:

ASP. NET_SessionId = rrwjbhbv 1w4qgm553usoqqq3; MyCook = visitCount = 1

Use the following script to search for the "ASP. NET_SessionId" field in the URI to obtain the sessionID and maintain the session.

When HTTP_REQUEST {

Set session_id [findstr [HTTP: uri] "ASP. NET_SessionId =" 18 ";"]

If {($ session_id eq ") and ([HTTP: cookie exists ASP. NET_SessionId])} {

Set session_id [HTTP: cookie ASP. NET_SessionId]

}

If {$ session_id ne ""}{

Persist uie $ session_id

}

}

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111621M17-1.jpg "style =" float: none; "title =" aflex1.jpg "alt =" 215658948.jpg"/>

The above are only script applications that are frequently encountered in the HTTP environment. The strength of the script tool is far more than that. In this case, we hope more technical colleagues can appreciate the charm of the script tool, compile more powerful script examples and make common progress.


ZJM)




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.