Citrix ADC

高级策略表达式和策略的总结示例

下表提供了高级策略表达式的示例,您可以将其用作自己的高级策略表达式的基础。

表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 (. exe) http.req.url.contains (.cfm) http.req.url.contains http.req.url.contains(“.ex”)(“.shtml”)http.req.url.contains http.req.url.contains(“.htx”)(“/目录/”)http.req.url.contains 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("vnd.ms-excel") http.res.header("Content-Type").contains("application/ msword");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://和https://在HTTP响应的主体中。 添加重写操作httpRewriteAction replace_all http.res.body(50000)"\"https://\"" -search 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\"" -search abcd add rewrite policy abcdTo1234Policy "http.req.body(1000).contains(\"abcd\")" abcdTo1234Action绑定重写全局abcdTo1234Policy 100 END -type REQ_OVERRIDE
将HTTP版本降级到1.0,以防止服务器分块HTTP响应。 add rewrite action downgradeTo1.0Action replace http.req.version.minor "\"0\"" add rewrite policy downgradeTo1.0Policy "http.req.version.minor.eq(1)" downgradeTo1.0Action bind lb vserver myLBVserver -policyName downgradeTo1.0Policy -priority 100 - gotopriityexpression NEXT -type REQUEST
在所有响应中删除对HTTP或HTTPS协议的引用,以便如果用户的连接是HTTP,则使用HTTP打开链接,如果用户的连接是HTTPS,则使用HTTPS打开链接。 添加重写动作remove_http_https replace_all "http.res.body(1000000).set_text_mode(ignorecase)""\"//\"" - 搜索“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:。 add responder action httptohttps:// action redirect "\"https://\" + http.req.hostname + http.req. "add responder policy httptohttppolicyIS_SSL" httptohttppolicy action bind responder global httptohttppolicy 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\"" add responder policy appendFile5Policy "http.req.url.eq(\"/testsite\")" appendFile5Action bind responder global appendFile5Policy 1 END -type OVERRIDE
将外部URL重定向到内部URL。 添加重写操作act_external_to_internalserver' '"www.my.host.com"' add rewrite policy pol_external_to_internal 'http.req.hostname.server.eq("www.external.host.com")' act_external_to_internal绑定重写全局pol_external_to_internal 100 END -type REQ_OVERRIDE
将具有www.Webn.example.com查询字符串的请求重定向到www.example.com。n的值来自查询字符串中的服务器参数,例如server=5。 添加重写操作act_redirect_query取代问# http.req.header(“主机”).before_str(“.example.com”)的“网络”+ http.req.url.query.value(“服务器”)#添加重写策略pol_redirect_query问# http.req.header .eq(“主机”)(“www.example.com”)& & http.req.url.contains ' act_redirect_query #(“?”)
限制一个URL每秒的请求数量。 add ns limitSelector ip_limit_selector http.req.url "client.ip。src“添加ns limitIdentifier ip_limit_identifier时间片)3600模式request_rate -limitType光滑-selectorName ip_limit_selector添加响应器动作my_Web_site_redirect_action redirect”\“http://www.mycompany.com/ \”“添加响应者政策ip_limit_responder_policy http.req.url.contains(\“myasp.asp \”)& &系统。check_limit (\"ip_limit_identifier\")" my_Web_site_redirect_action bind responder global ip_limit_responder_policy 100 END -type default
检查客户端IP地址,但不修改请求而通过请求。 添加重写策略check_client_ip_policy 'HTTP.REQ.HEADER ("x-forward -for")。存在HTTP.REQ.HEADER(“客户端ip”)。EXISTS' NOREWRITE bind rewrite global check_client_ip_policy 100结束
从请求中删除旧的头并插入一个NS-Client头。 add rewrite action del_x_forwarded_for delete_http_header x-forwarded-for 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 rewrite policy check_client_ip_policy 'HTTP.REQ.HEADER("client-ip")。EXISTS' del_client_ip add rewrite action insert_ns_client_header insert_http_header NS-Client 'CLIENT.IP. txt '。SRC' add rewrite policy 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-Client报头,然后修改“插入报头”操作,以便插入报头的值包含旧报头中的客户端IP值和Citrix ADC设备的连接IP地址。注意,除了最后的set重写操作外,本示例重复了前面的示例。 ' add rewrite action del_x_forwarded_for delete_http_header x-forward -for add rewrite action del_client_ip delete_http_header client-ip add rewrite policy check_x_forwarded_for_policy ' HTTP.REQ.HEADER(" x-forward -for ")。存在' del_x_forwarded_for add rewrite policy check_client_ip_policy ' HTTP.REQ.HEADER(" client-ip ")。EXISTS ' del_client_ip add rewrite action insert_ns_client_header insert_http_header NS-Client ' CLIENT.IP. txt '。SRC ' add rewrite policy insert_ns_client_policy ' HTTP.REQ.HEADER(" x-forward -for ")。存在HTTP.REQ.HEADER(“客户端ip”)。存在“insert_ns_client_header绑定改写全球check_x_forwarded_for_policy 100 200绑定改写全球check_client_ip_policy 200 300绑定改写300年全球insert_ns_client_policy结束设置重写行动insert_ns_client_header -stringBuilderExpr”HTTP.REQ.HEADER(“x-forwarded-for”)value (0 ) + “ “ + HTTP.REQ.HEADER(客户端ip) value (0) + "+ CLIENT.IP.SRC’
高级策略表达式和策略的总结示例