NetScaler

默认语法表达式和策略的摘要示例

下表提供了默认语法表达式的示例,您可以将其用作自己的默认语法表达式的基础。

表1。默认语法表达式示例

表达式类型 示例表达式
看看HTTP请求中使用的方法。 http.req.method.eq (post) http.req.method.eq(得到)
检查HTTP请求(req)或响应(res)中的Cache-Control或Pragma头值。 http.req.header (cache - control) .contains(“没有商店”)http.req.header (cache - control) .contains(“no - cache”)http.req.header(“杂注”).contains(“no - cache”)http.res.header (cache - control) .contains(“私人”)http.res.header (cache - control) .contains(“公共”)http.res.header (cache - control) .contains (must-revalidate) http.res.header (cache - control)。包含(“proxy-revalidate”)http.res.header (cache - control) .contains(“信息”)
检查请求(req)或响应(res)中是否存在标头。 http.req.header(“到了头”)。存在http.res.header .exists(“到了头”)
根据文件扩展名在HTTP请求中查找特定的文件类型。 Http.req.url.contains (".html") Http.req.url.contains (".cgi") Http.req.url.contains (".asp") Http.req.url.contains (".cfm") Http.req.url.contains (". shhtml ") Http.req.url.contains (".html") Http.req.url.contains (".cgi -bin/") Http.req.url.contains ("/cgi-bin/") Http.req.url.contains ("/exec/") Http.req.url.contains ("/bin/")
在HTTP请求中查找除特定文件类型以外的任何内容。 http.req.url.contains (gif)自身之外;http.req.url.contains (jpeg)自身之外
根据Content-Type头检查在HTTP响应中发送的文件类型。 http.res.header(“内容类型”).contains http.res.header(“文本”)(“内容类型”)。http.res.header("Content-Type").contains("application/vnd.ms-powerpoint");http.res.header(“内容类型”).contains (" text / css ");http.res.header(“内容类型”).contains (" text / xml ");http.res.header(“内容类型”).contains(“图像/”)
检查此响应是否包含过期头。 “http.res.header .exists(“到期”)
检查响应中的Set-Cookie头。 http.res.header .exists (set - cookie”)
检查发送响应的代理。 http.res.header(“用户代理”).contains (Mozilla / 4.7) http.res.header .contains(“用户代理”)(“MSIE”)
检查请求正文的前1024字节是否以字符串" some text "开头。 http.req.body(1024)。(包含一些文本)

下表显示了常用函数的策略配置和绑定示例。

表2。默认语法表达式和策略示例

目的 例子
使用重写特性来替换出现的http:// with https://在HTTP响应的正文中。 添加重写动作http.res.body(50000)"https://\"" -pattern http:// add rewrite policy demo_rep34312 "http.res.body(50000).contains(\"http://\")" httpRewriteAction .
将HTTP正文前1000字节中出现的所有" abcd "替换为" 1234 "。 添加重写动作abcdTo1234Action replace_all "http.req.body(1000)""\"1234\"" -pattern abcd add rewrite policy abcdTo1234Policy "http.req.body(1000).contains(\"abcd\")" abcdTo1234Action bind rewrite global abcdTo1234Policy 100 END -type REQ_OVERRIDE .
将HTTP版本降级为1.0以防止服务器对HTTP响应进行分块处理。 添加重写操作downgradeTo1.0Action替换http.req.version.minor "\"0\""添加重写策略downgradeTo1.0Policy "http.req.version.minor.eq(1)" downgradeTo1.0Action绑定lb vserver myLBVserver -policyName downgradeTo1.0Policy -priority 100 -gotoPriorityExpression NEXT -type REQUEST
删除所有响应中对HTTP或HTTPS协议的引用,这样,如果用户的连接是HTTP,则使用HTTP打开链接,如果用户的连接是HTTPS,则使用HTTPS打开链接。 添加重写动作remove_http_https replace_all "http.res.body(1000000).set_text_mode(ignorecase)""\"//\"" -pattern "re~https?://| https?://~" add rewrite policy remove_http_https true remove_http_https bind lb vserver test_vsvr -policyName remove_http_https -priority 20 -gotoPriorityExpression NEXT -type RESPONSE
将所有url中的http:实例重写为https:。 添加responder action httptohttpaction重定向"\"https://\" + http.req.hostname + http.req。CLIENT.SSL. url" -bypassSafetyCheck是添加响应策略httpToHttpsPolicy "!IS_SSL" httptohttpaction bind responder global httpToHttpsPolicy 1 END -type OVERRIDE
修改URL,使其从URL a重定向到URL b。在本例中,“file5.html”被附加到路径后。 添加响应器动作appendFile5Action重定向\"http://\" + http.req.hostname + http.req.url + \"/file5.html\" -bypassSafetyCheck是添加响应器策略appendFile5Policy "http.req.url.eq(\"/testsite\")" appendFile5Action绑定响应器全局appendFile5Policy 1 END -type OVERRIDE
将外部URL重定向到内部URL。 添加重写动作act_external_to_internal REPLACE 'http.req.hostname。添加重写策略pol_external_to_internal 'http.req.hostname.server.eq("www.external.host.com")' act_external_to_internal bind重写全局pol_external_to_internal 100 END -type REQ_OVERRIDE
将查询字符串指向www.Webn.example.com的请求重定向到www.example.com。n来源于查询字符串中的server参数,例如server=5。 添加重写动作act_redirect_query替换q#http.req.header("Host").before_str("。example.com")' '"Web" + http.req.url.query.value("server")#添加重写策略pol_redirect_query q#http.req.header("Host").eq("www.example.com") && http.req.url.contains("?")' act_redirect_query#
限制每秒来自URL的请求数。 添加ns limitSelector ip_limit_selector http.req.url "client.ip。“add ns limit_dentifier ip_limit_identifier -threshold 4 -timeSlice 3600 -mode request_rate -limitType smooth -selectorName ip_limit_selector add responder action my_Web_site_redirect_action redirect”\"http://www.mycompany.com/\"" add responder policy ip_limit_responder_policy "http.req.url.contains(\"myasp.asp\") && sys.check_limit (\"ip_limit_identifier\")" my_Web_site_redirect_action绑定responder global ip_limit_responder_policy 100 END -type default
检查客户端IP地址,不修改请求,通过请求。 添加重写策略check_client_ip_policy 'HTTP.REQ.HEADER ("x-forwarded-for")。存在HTTP.REQ.HEADER ("client-ip")。EXISTS' NOREWRITE bind重写全局check_client_ip_policy 100结束
从请求中删除旧的报头,并插入一个NS-Client报头。 添加重写动作del_client_ip delete_http_header client-ip添加重写策略check_x_forwarded_for_policy 'HTTP.REQ.HEADER("x-forwarded-for")。存在' del_x_forwarded_for add重写策略check_client_ip_policy 'HTTP.REQ.HEADER("client-ip")。EXISTS' del_client_ip添加重写动作insert_ns_client_header insert_http_header NS-Client 'CLIENT.IP。SRC' add重写策略insert_ns_client_policy 'HTTP.REQ.HEADER("x-forwarded-for")存在HTTP.REQ.HEADER(“客户端ip”)。EXISTS' insert_ns_client_header bind重写全局check_x_forwarded_for_policy 100 200 bind重写全局check_client_ip_policy 200 300 bind重写全局insert_ns_client_policy 300 END
从请求中删除旧的报头,插入NS-Client报头,然后修改“插入报头”操作,以便插入的报头的值包含来自旧报头的客户端IP值和NetScaler设备的连接IP地址。注意,这个示例重复了前面的示例,除了最后一个集合重写操作。 添加重写动作del_client_ip delete_http_header client-ip添加重写策略check_x_forwarded_for_policy 'HTTP.REQ.HEADER("x-forwarded-for")。存在' del_x_forwarded_for add重写策略check_client_ip_policy 'HTTP.REQ.HEADER("client-ip")。EXISTS' del_client_ip添加重写动作insert_ns_client_header insert_http_header NS-Client 'CLIENT.IP。SRC' add重写策略insert_ns_client_policy 'HTTP.REQ.HEADER("x-forwarded-for")存在HTTP.REQ.HEADER(“客户端ip”)。EXISTS' insert_ns_client_header bind重写全局check_x_forwarded_for_policy 100 200 bind重写全局check_client_ip_policy 200 300 bind重写全局insert_ns_client_policy 300 END set重写动作insert_ns_client_header -stringBuilderExpr 'HTTP.REQ.HEADER("x-forwarded-for"). value (0) + " " + HTTP.REQ.HEADER("client-ip"). value (0) + " " + CLIENT.IP. EXISTS' ' insert_ns_client_header bind重写全局check_client_ip_policy ' 'SRC' -bypassSafetyCheck是
默认语法表达式和策略的摘要示例

在本文中