当前位置:网站首页>简单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编程宝典》
边栏推荐
- 網絡中的一些基本概念
- Some basic concepts in network
- 实验三 继承性和派生类
- 2022/07/12 learning notes (day05) cycle
- Some problems encountered in work
- Talking about several solutions of cross domain
- Handle Chinese word segmentation IK word segmenter and expand and stop dictionary
- DSL realizes automatic completion query
- Busybox 1.21.1 has udpsvd function, which can be compiled successfully without interfering with the local busybox method
- Cygwin 配合 Listary 切换当前目录快速打开
猜你喜欢
随机推荐
[force buckle] realize queue with stack
Experiment class II and object definition initialization
EOG-based eye movement detection and gaze estimation for an asynchronous virtual keyboard基于EOG的异步虚
Salgaze: personalized gaze estimation using visual saliency
Quelques concepts de base dans le réseau
颜色直方图 灰度图&彩色图
读取图片 进行空间转换 展现不同颜色空间
Read pictures and convert them to show different color spaces
斑点检测 记录
一种基于凝视的平板电脑手势控制系统的设计与实现
Typescript learning
2022/07/10 group 5 Ding Shuai's study notes day03
EOG based eye movement detection and gaze estimation for an asynchronous virtual keyboard
Some basic concepts in network
Solution: unable to load file c:\program files\ Because running scripts is forbidden on this system
实验一 简单程序设计
二分查找及其引申
工作中遇到的一些问题
Part of the second Shanxi Network Security Skills Competition (Enterprise Group) WP (IV)
Talking about several solutions of cross domain







