当前位置:网站首页>简单irules编写 入门级
简单irules编写 入门级
2022-07-17 05:20:00 【渣渣今天学废了吗】
可能有错,还烦请指出
irules作用:系统对数据控制有更精细的定制要求;对标准协议的功能支持有更高的要求
irules使用TCL语句:
#:注释,以;或换行结束
[命令](命令嵌套时使用[])
::全局变量声明符
class:全局数组变量,四种类型:address(IP地址)、string(字符串)、integer(数值)、external fail(外部文件);
matchclass:匹配语句,参数2为匹配条件,1和3为匹配参数
置换符:$
(例
set a 100
set b $a
将a的值给b
),设置或改变变量值时不需要:$
双引号中:{}中字符按照普通字符处理
(例:
set b {
$a + 2}
expr $b*4
得出结果为a+2*4
若想要输出结果为(a+2)*4
set b {
[expr$a+2]}
expr $b*4
)
操作符
Irules中包含事件:
When HTTP_REQUEST{
}
When HTTP_RESPONSE{
}
[HTTP::uri]:HTTP代表HTTP协议,uri表示取这个访问中的uri,::表示从属关系,uri属于 HTTP命令体系
常用逻辑体系:
if{
}{
}elseif{
}
else{
}
Switch(options)<>{
Case string:
<>
Break;
Default:
<>
Break;
}
输出log:log[<facility>.<level>]<message>
#注意空格缩进
一些简单Irules:
1、删除response Header头内容
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、负载:根据不同地址分配到不同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、根据不同uri负载到不同的pool
When HTTP_REQUEST{
If{
[HTTP::uri] contains “数据” }{
Pool 指定pool
}else{
Pool all_pool}
}
}
3、插入X-Forward-for
when HTTP_RESPONSE {
HTTP::header insert X-Forwarded-For [IP::remote_addr]]
}
4、修改页面返还内容
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
}
}
5、禁用事件
event disable
6、添加优先级
when HTTP_RESPONSE priority 100 {
7、重定向
When HTTP_REQUEST{
If{
[HTTP::uri] contains “关键字”}{
HTTP::redirect”https://[HTTP::host][HTTP::uri]”
}
}
8、包含关键字访问a,否则访问b:
When HTTP_REQUEST{
If{
[HTTP::uri] contains “关键字”}{
HTTP::redirect”https://a.com”
}else{
HTTP::redirect”https://b.com}
}
}
9.1、会话保持 基于header头
例:
header包头
When HTTP_REQUEST{
If{
[HTTP::header “header头内字段”] !=”” }{
Persist uie [HTTP::header “header头内字段”]
}
}
9.2、基于cookie(session ID)会话保持
10、示例
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
}
}
参考:《Irules编程宝典》
边栏推荐
- 机器人缝合手势识别和分类
- 阿拉伯数字转中文
- TCP协议
- Vscode Tips 1
- Restapi implements aggregation (dark horse tutorial)
- 山西省第二届网络安全技能大赛(企业组)部分赛题WP(二)
- Vscode one dark and C extended variable color conflict settings JSON is as follows
- Preparation of blast Library of rust language from scratch (1) -- Introduction to the basics of blas
- [force buckle] single valued binary tree
- 吴恩达机器学习第12-13章
猜你喜欢

Résoudre le problème de l'ambiguïté de la cible dans l'interaction de fixation 3D par l'estimation de la profondeur vor

无80和443端口下申请域名SSL证书(适用于 acme.sh 和 certbot)
![[force buckle] copy the linked list with random pointer](/img/ed/eb54aad302da3aaac7e1d583770ca0.png)
[force buckle] copy the linked list with random pointer

网络层及ip学习

No application for domain name SSL certificate under ports 80 and 443 (applicable to acme.sh and certbot)

Spot detection record

wireshark抓包:错误分析

阿拉伯数字转中文

Design and implementation of a gesture control system for tablet computer based on gaze

Color histogram grayscale image & color image
随机推荐
Seachest utilities tool enables your hard disk to consume less power and live longer
Quantum three body problem: an overview of numerical computation
CUDA与大数组的双调排序
实验五: GUI
山西省第二届网络安全技能大赛(企业组)部分赛题WP(四)
[force buckle] flip binary tree
过拟合原因及解决办法
Key points of embedded C language (const, static, volatile, bit operation)
2022/07/09 group 5 Ding Shuai's study notes day02
2022/07/12 learning notes (day05) cycle
Restclient multi conditional aggregation
吴恩达机器学习第8-9章
SeaChest Utilities 工具,让你的硬盘功耗又低又长寿
網絡中的一些基本概念
Busybox 1.21.1 has udpsvd function, which can be compiled successfully without interfering with the local busybox method
Design and implementation of a gesture control system for tablet computer based on gaze
基于视觉显著性的外观注视估计
[force buckle] single valued binary tree
吴恩达机器学习第12-13章
Leetcode tree