当前位置:网站首页>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 》
边栏推荐
- How to make good use of cost compensation contract in government procurement
- 渣渣学习之路(1)输出某年某月的日历页
- Information on successful cooperation between CS brand sdnand and stm32mcu
- oracle中merge into 与update的性能对比
- 渣渣学习之路(2)纯小白向:Win Server 2003服务器搭建
- 《PyTorch深度学习实践》-B站 刘二大人-day7
- redis
- Why do solution providers "love" CS Genesis SD NAND
- 吴恩达机器学习第6-7章
- F5LTM(一)逻辑关系图
猜你喜欢
随机推荐
Quelques concepts de base dans le réseau
Some basic concepts in network
Sword finger offer brush questions
通过数据加密方案阻止勒索攻击
wireshark抓包:报文信息
Temperature acquisition experiment and experimental experience based on I2C
Experiment 3 inheritance and derived classes
Release nohup Out disk space occupied
吴恩达机器学习第14-15章
OLED data display based on spi/iic interface
Machine learning - classification prediction of logistic regression
Hand in hand building a home NAS universal server (1) | configuration selection and preparation
DSL implements metrics aggregation
小迪网络安全笔记 信息收集-CDN绕过技术(7)
Why do solution providers "love" CS Genesis SD NAND
️️固高运动控制卡的相关知识点
Learning about STM assembler design
释放nohup.out占用的磁盘空间
用Altium Designer绘制PCB图
IDEA中@Resource爆红








