本文通过样例为您介绍通过CLI工具使用边缘脚本的操作方法,包括在CLI工具下进行规则的编写、保存、测试和发布的基本操作。
说明 CLI工具的使用方法,请参见通过CLI工具使用边缘脚本。
边缘脚本的基本操作如下:
- 将编写的边缘脚本规则存储为本地文件
例如:m3u8.es规则拦截所有.m3u8请求
$cat m3u8.es if eq(substr($uri, -5, -1), '.m3u8') { add_rsp_header('X-DEBUG-DENY-REASON', 'block m3u8') exit(400) }
- 发布规则至模拟环境
$./es.py action=push_test_env domain=<your domain> rule='{"pos":"head","pri":"0","rule_path":"./m3u8.es","enable":"on"}' Response Code: ============= 200 OK Response Info: ============== { "RequestId": "FB98CC67-8FBA-44CF-A98A-BCE3B19FE510" }
- 查看模拟环境的规则列表
$./es.py action=query_test_env domain=<your domain> Response Code: ============= 200 OK Response Info: ============== { "DomainConfigs": [ { "Status": "success", # Status为success时,表示规则已成功设置 "ConfigId": 17432558, "FunctionArgs": [ { "ArgName": "enable", "ArgValue": "on" }, { "ArgName": "pri", "ArgValue": "0" }, { "ArgName": "pos", "ArgValue": "head" }, { "ArgName": "rule", "ArgValue": "if eq(substr($uri, -5, -1), '.m3u8') {\n add_rsp_header('X-DEBUG-DENY-REASON', 'block m3u8')\n exit(400)\n}\n" } ], "FunctionName": "dsl_ex" } ], "RequestId": "4DDBF3DB-BCAC-4074-AC1E-B6C1F1C6CBFB" }
- 测试规则
$curl -x 模拟环境IP:80 -o /dev/null -v 'http://www.archnote.net/test.m3u8' < HTTP/1.1 400 Bad Request < Server: Tengine < Date: Thu, 18 Jul 2019 09:40:41 GMT < Content-Type: text/html < Content-Length: 265 < Connection: close < X-DEBUG-DENY-REASON: block m3u8 < Via: cache1.cn1191-1[,0] < Timing-Allow-Origin: * < EagleId: 2a7b771b15634428415537484e
- 发布规则至生产环境
$./es.py action=push_product_env domain=<your domain> Response Code: ============= 200 OK Response Info: ============== { "RequestId": "F4B378F8-6AAE-457A-A70C-E856ED8341D8" }
- 查看生产环境的规则列表
$./es.py action=query_product_env domain=<your domain> Response Code: ============= 200 OK Response Info: ============== { "DomainConfigs": { "DomainConfig": [ { "Status": "success", "ConfigId": 17432558, "FunctionArgs": { "FunctionArg": [ { "ArgName": "enable", "ArgValue": "on" }, { "ArgName": "pri", "ArgValue": "0" }, { "ArgName": "pos", "ArgValue": "head" }, { "ArgName": "rule", "ArgValue": "if eq(substr($uri, -5, -1), '.m3u8') {\n add_rsp_header('X-DEBUG-DENY-REASON', 'block m3u8')\n exit(400)\n}\n" } ] }, "FunctionName": "dsl_ex" } ] }, "RequestId": "36D57C1D-C820-43DA-8E70-DADC4B8BD4DD" }