Citrix ADC

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

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

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

表达式类型 示例表达式
查看HTTP请求中使用的方法。 http.req.method.eq (post) http.req.method.eq(得到)
检查HTTP请求(req)或响应(res)中的缓存控制或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 (".asp") Http.req.url.contains (".cfm") Http.req.url.contains (".cfm") Http.req.url.contains (". exml ") Http.req.url.contains (".shtml") Http.req.url.contains (".html") Http.req.url.contains (".html") Http.req.url.contains ("/exec/") Http.req.url.contains ("/bin/")
在HTTP请求中查找除特定文件类型以外的任何内容。 http.req.url.contains (gif)自身之外;http.req.url.contains (jpeg)自身之外
根据内容类型标头检查正在HTTP响应中发送的文件的类型。 http.res.header(“内容类型”).contains http.res.header(“文本”)(“内容类型”)。包含"application/msword") http.res.header("Content-Type").contains("vnd.ms-excel");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字节是否以字符串"某些文本"开头。 http.req.body(1024)。(包含一些文本)

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

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

用途 示例
使用重写功能可替换HTTP响应正文中出现的http://和https:// 添加http.res.body(50000)"\"https://\"" -pattern http:// add重写策略demo_rep34312 "http.res.body(50000).contains(\"http://\")" httpRewriteAction .
在HTTP正文的前1000个字节中,将所有出现的" abcd "替换为" 1234 "。 添加重写动作abcdTo1234Action replace_all“http.req.body(1000)”"\"1234\"" -pattern abcd add重写策略abcdTo1234Policy "http.req.body(1000).contains(\"abcd\")" abcdTo1234Action绑定重写全局abcdTo1234Policy 100 END -type REQ_OVERRIDE .
将HTTP版本降级为1.0,以防止服务器对HTTP响应进行分块处理。 add重写动作downgradeTo1.0Action replace http.req.version.minor "\"0\"" add重写策略downgradeTo1.0Policy "http.req.version.minor.eq(1)" downgradeTo1.0Action bind 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)""\"//\"" - 模式”~ 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
将http的实例重写到https:在所有URL中。 添加响应器动作httptohttpaction重定向“\”https://\”+ http.req.hostname + http.req。-bypassSafetyCheck YES add responder policy httpToHttpsPolicy !IS_SSL" httptohttpaction绑定响应器全局httpToHttpsPolicy 1 END -type OVERRIDE
修改url以从url a重定向到url b。在此示例中,“file5.html”会附加到路径中。 add responder action appendFile5Action redirect \"http://\" + http.req.hostname + http.req.url + \"/file5.html\"" -bypassSafetyCheck YES添加responder policy appendFile5Policy "http.req.url.eq(\"/testsite\")" appendFile5Action绑定responder global appendFile5Policy 1 END -type OVERRIDE
将外部url重定向到内部url。 添加重写动作act_external_to_internal替换http.req.hostname。server' ' ' '"www.my.host.com"' add rewrite policy pol_external_to_internal 'http.req.hostname.server.eq("www.external.host.com")' act_external_to_internal bind rewrite global pol_external_to_internal 100 END -type REQ_OVERRIDE . http.req.hostname.server.eq("www.external.host.com")
将请求重定向到具有查询字符串的www.example.com。值n从查询字符串中的服务器参数派生,例如,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.urlsrc" add ns limitIdentifier 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. response "check_limit (\"ip_limit_identifier\")" my_Web_site_redirect_action绑定响应器全局ip_limit_responder_policy 100结束-type默认
检查客户端IP地址,但在不修改请求的情况下传递请求。 添加重写策略check_client_ip_policy 'HTTP.REQ.HEADER ("x-forward -for")。存在HTTP.REQ.HEADER(“客户端ip”)。EXISTS' NOREWRITE bind重写全局check_client_ip_policy 100结束
从请求中删除旧标头并插入ns -客户端标头。 add rewrite action del_client_ip delete_http_header client-ip add rewrite policy 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")。' del_client_ip add rewrite action ' insert_ns_client_header ' insert_http_header ' NS-Client 'CLIENT.IP。SRC'添加重写策略insert_ns_client_policy 'HTTP.REQ.HEADER("x-forward -for")。存在HTTP.REQ.HEADER(“客户端ip”)。EXISTS' insert_ns_client_header bind rewrite global check_x_forwarded_for_policy 100 200 bind rewrite global check_client_ip_policy 200 300 bind rewrite global insert_ns_client_policy 300 END
从请求中删除旧标头,插入NS -客户端标头,然后修改“插入标头”操作,以便插入标头的值包含旧标头和Citrix ADC设备的连接IP地址中的客户端IP值。请注意,此示例重复前面的示例,但最终集合重写操作除外。 add rewrite action del_client_ip delete_http_header client-ip add rewrite policy 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")。' del_client_ip add rewrite action ' insert_ns_client_header ' insert_http_header ' NS-Client 'CLIENT.IP。SRC'添加重写策略insert_ns_client_policy 'HTTP.REQ.HEADER("x-forward -for")。存在HTTP.REQ.HEADER(“客户端ip”)。EXISTS' insert_ns_client_header bind rewrite global check_x_forwarded_for_policy 100 200 bind rewrite global check_client_ip_policy 200 300 bind rewrite global insert_ns_client_policy 300 END set rewrite action insert_ns_client_header -stringBuilderExpr 'HTTP.REQ.HEADER("x-forward -for"). value (0) + " " + HTTP.REQ.HEADER("client-ip"). value (0) + " " + CLIENT.IP。SRC的-bypassSafetyCheck是的
默认语法表达式和策略的摘要示例

在本文中