当前位置:网站首页>Entry level of simple irules writing
Entry level of simple irules writing
2022-07-19 06:49:00 【Did you learn to waste today】
There may be a mistake , Please also point out
irules effect : The system has more refined customization requirements for data control ; There are higher requirements for the functional support of standard protocols
irules Use TCL sentence :
#: notes , With ; Or end of line feed
[ command ]( When commands are nested, use [])
:: Global variable declarator
class: Global array variables , Four types :address(IP Address )、string( character string )、integer( The number )、external fail( External file );
matchclass: Match statement , Parameters 2 For matching conditions ,1 and 3 For matching parameters
Permutation character :$
( example
set a 100
set b $a
take a The value of b
), There is no need to :$
In double quotes :{} Chinese characters are treated as ordinary characters
( example :
set b {
$a + 2}
expr $b*4
The result is a+2*4
If you want to output the result as (a+2)*4
set b {
[expr$a+2]}
expr $b*4
)
The operator
Irules Contains Events :
When HTTP_REQUEST{
}
When HTTP_RESPONSE{
}
[HTTP::uri]:HTTP representative HTTP agreement ,uri It means to take the uri,:: Denotes subordination ,uri Belong to HTTP Command system
Common logic systems :
if{
}{
}elseif{
}
else{
}
Switch(options)<>{
Case string:
<>
Break;
Default:
<>
Break;
}
Output log:log[<facility>.<level>]<message>
# Notice the space indent
Simple Irules:
1、 Delete response Header Head content
when HTTP_RESPONSE {
log local0. "Removing unwanted headers - $RequestedURL"
HTTP::header remove "Server"
HTTP::header remove "X-Powered-By"
HTTP::header remove "X-Pad"
}
2.1、 load : According to different addresses assigned to different pool
when HTTP_REQUEST {
if {
[IP::addr [IP::remote_addr] equals 10.10.X.0/24] } {
Log local0. "Load balancing to in_network_http_pool"
pool /Common/in_network_http_pool
} else {
log local0. "Load balancing to out_network_http_pool"
pool /Common/out_network_http_pool
}
}
2.2、 According to the different uri Load to different pool
When HTTP_REQUEST{
If{
[HTTP::uri] contains “ data ” }{
Pool Appoint pool
}else{
Pool all_pool}
}
}
3、 Insert X-Forward-for
when HTTP_RESPONSE {
HTTP::header insert X-Forwarded-For [IP::remote_addr]]
}
4、 Modify the return content of the page
when HTTP_RESPONSE {
if {
[HTTP::status] eq "404" } {
log local0. "HTTP 404 on $RequestedURL"
HTTP::respond 200 content "<html> <head><title>Apology Page</title></head> <body>Oops,I got lost( The modified page )</body> </html>"
event disable
}
}
5、 Disable Events
event disable
6、 Add priority
when HTTP_RESPONSE priority 100 {
7、 Redirect
When HTTP_REQUEST{
If{
[HTTP::uri] contains “ keyword ”}{
HTTP::redirect”https://[HTTP::host][HTTP::uri]”
}
}
8、 Include keyword access a, Otherwise visit b:
When HTTP_REQUEST{
If{
[HTTP::uri] contains “ keyword ”}{
HTTP::redirect”https://a.com”
}else{
HTTP::redirect”https://b.com}
}
}
9.1、 Conversation retention be based on header head
example :
header baotou
When HTTP_REQUEST{
If{
[HTTP::header “header Field in header ”] !=”” }{
Persist uie [HTTP::header “header Field in header ”]
}
}
9.2、 be based on cookie(session ID) Conversation retention
10、 Example
when HTTP_REQUEST {
if {
[IP::addr [IP::remote_addr] equals 10.10.4.0/24] } {
log local0. "Load balancing to in_network_http_pool"
pool /Common/in_network_http_pool
} else {
log local0. "Load balancing to out_network_http_pool"
pool /Common/out_network_http_pool
}
log local0. "Inserting XFF header for [IP::remote_addr]"
HTTP::header insert X-Forwarded-For [IP::remote_addr]
set RequestedURL [HTTP::host][HTTP::uri]
}
when HTTP_RESPONSE {
if {
[HTTP::status] eq "404" } {
log local0. "HTTP 404 on $RequestedURL"
HTTP::respond 200 content "<html> <head><title>Apology Page</title></head> <body>Oops,I got lost</body> </html>"
event disable
}
}
Reference resources :《Irules Programming book 》
边栏推荐
- Es aggregation analysis reports an error: "reason": "text fields are not optimized for operations
- 吴恩达机器学习第1-2章
- Restapi implementation of automatic completion & case implementation (search box input for automatic completion)
- tail -f暂停方法
- Causes and solutions of over fitting
- Restclient multi conditional aggregation
- Programming learning based on ardunio ide software development
- DSL implements metrics aggregation
- DSL implements bucket aggregation
- Machine learning - classification prediction of logistic regression
猜你喜欢
随机推荐
Part of the second Shanxi Network Security Skills Competition (Enterprise Group) WP (III)
SQL constraints
Set the index library structure, add suggestions that can be automatically completed to users, and turn some fields into collections and put them into suggestions
Tcp/ip protocol learning
基于SPI/IIC接口的OLED数据显示
Openssl--- stack
redis
Share the successful cooperation between CS brand sdnand and wearable devices
网络中的一些基本概念
渣渣学习之路(1)输出某年某月的日历页
Restclient query document
Wu Enda machine learning chapter 14-15
Wu Enda machine learning chapter 3-4
Application case of CS brand sdnand in color detector industry
ORACLE分组排序后获取第一条和最后一条值
Loadng class `com. mysql. jdbc. Driver‘. This is deprecated. The new driver class is `com. mysql. cj. jdb
Hand in hand building a home NAS universal server (1) | configuration selection and preparation
Pytorch deep learning practice-b station Liu erden-day3
Part of the second Shanxi Network Security Skills Competition (Enterprise Group) WP (I)
F5LTM(一)逻辑关系图









