规则引擎配置
更新时间:2026-09-07
设置规则引擎配置
您可以参考API文档获取参数的详细信息:设置规则引擎配置
Python
1def test_set_site_page_rules_full(eo_client):
2 """
3 set the rule engine config with all supported match types and config items.
4 This is a full field reference, note that some config items are not
5 supported by some match types, so a real rule should be split by match type.
6 """
7 page_rules = [
8 {
9 'name': 'example',
10 'status': 'ON',
11 'rules': [
12 # conditions in one group are joined by 'and'
13 [
14 {'matchFrom': 'path', 'operator': 'inValues',
15 'values': ['/test'], 'ignoreCase': True},
16 {'matchFrom': 'directory', 'operator': 'inValues',
17 'values': ['/test/']},
18 {'matchFrom': 'arg', 'operator': 'inValues',
19 'matchKey': 'test', 'values': ['abc']},
20 {'matchFrom': 'suffix', 'operator': 'inValues',
21 'values': ['jpg']},
22 {'matchFrom': 'header', 'operator': 'inValues',
23 'matchKey': 'user-agent', 'values': ['test']},
24 {'matchFrom': 'fullUrl', 'operator': 'inValues',
25 'values': ['/test/test.txt']},
26 {'matchFrom': 'basename', 'operator': 'inValues',
27 'values': ['test.mp4']},
28 {'matchFrom': 'remoteGeos', 'operator': 'inValues',
29 'values': [{'pro': 'beijing'}, {'cty': 'bt'}]},
30 {'matchFrom': 'remoteAddrs', 'operator': 'inValues',
31 'values': ['1.2.3.4', '172.16.0.0/12']},
32 {'matchFrom': 'remoteIsp', 'operator': 'inValues',
33 'values': 'cm|un|ct'},
34 {'matchFrom': 'method', 'operator': 'inValues',
35 'values': ['GET', 'POST']},
36 {'matchFrom': 'cookie', 'operator': 'inValues',
37 'matchKey': 'test', 'values': ['abc']},
38 {'matchFrom': 'host', 'operator': 'inValues',
39 'values': ['1.test.com']}
40 ],
41 # groups are joined by 'or'
42 [
43 {'matchFrom': 'path', 'operator': 'regex',
44 'values': '^/example/test[123]/$'},
45 {'matchFrom': 'arg', 'operator': 'exists',
46 'matchKey': 'test'}
47 ]
48 ],
49 'config': {
50 'cacheTtl': [
51 {'value': '/', 'weight': 100, 'override_origin': False,
52 'ttl': 0, 'type': 'path'}
53 ],
54 'cacheKey': {'query': False, 'ignore_case': True,
55 'include_args': ['a', 'b']},
56 'clientCacheTtl': {'mode': 'custom', 'ttl': 150},
57 'offlineMode': 'OFF',
58 'cacheCodeTtl': [
59 {'value': '404', 'weight': 100, 'overrideOrigin': True,
60 'ttl': 10, 'type': 'code'},
61 {'value': '400', 'weight': 100, 'overrideOrigin': True,
62 'ttl': 10, 'type': 'code'}
63 ],
64 'refreshRevalidate': {'enabled': True},
65 'httpToHttpsEnabled': 'ON',
66 'httpToHttpsCode': '302',
67 'hsts': {'maxAge': -1, 'includeSubDomains': False,
68 'preload': False},
69 'sslProtocols': ['TLSv1.0', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'],
70 'sslMode': 'custom',
71 'sslCipherList': 'TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256',
72 'ocsp': 'ON',
73 'isa': 'ON',
74 'http2Disable': 'OFF',
75 'http3': {'enable': False},
76 'webSocket': {'enabled': True, 'timeout': 10},
77 'http2Origin': 'ON',
78 'clientMaxBodySize': '1026',
79 'compress': 'ON',
80 'compressMethodArray': ['gzip', 'br'],
81 'clientResponse': {
82 'addHeaders': {'test': '${uri}', 'test2': '11'},
83 'removeHeaders': {'Content-Type': ''}
84 },
85 'originRequest': {
86 'addHeaders': {'test': '${uri}', 'test2': '11'},
87 'removeHeaders': {'Content-Type': ''}
88 },
89 'originConfig': [
90 {'addr': '1.1.1.1', 'httpPort': 80, 'type': 'IP',
91 'upstreamProtocol': 'http', 'host': 'test.eo.com'}
92 ],
93 # originPool and originConfig can not be set together
94 # 'originPool': {'originPoolId': 'geo_1qrUW3nppJIy',
95 # 'upstreamProtocol': 'http', 'httpPort': 80},
96 'originTimeout': {'loadTimeout': 10, 'connectTimeout': 5},
97 'originRedirectOptions': {'enableRedirectFollow': 'ON',
98 'maxRedirectFollowCount': 2},
99 'originOptions': {'range': 'force_all', 'partSize': '512k'},
100 'realIp': {'enabled': True, 'name': 'True-Client-Ip'},
101 'errorPage': [
102 {'code': 400, 'url': 'http://test.eo.com/400.html'},
103 {'code': 403, 'url': 'http://test.eo.com/403.html'}
104 ],
105 'trafficLimit': {'enable': True, 'limitRate': 1,
106 'limitStartHour': 10, 'limitEndHour': 19,
107 'limitRateUnit': 'k'},
108 'antiHotLink': {'antiType': 'typeA', 'secretKey': 'xxx',
109 'newsecretKey': 'xxx', 'timeout': 1800,
110 'timestampFormat': 'dec',
111 'authArg': 'auth_key'},
112 'originArg': {'ignore': True, 'args': []},
113 'urlRules': [
114 {'scheme': 'http', 'host': 'test.eo.com', 'status': 302,
115 'query': 'OFF', 'dstPath': '/test/1.txt'}
116 ]
117 }
118 }
119 ]
120 response = eo_client.set_site_page_rules(
121 site='test-sdk-eo.baidu.com',
122 pageRules=page_rules)
123 print(response)
注:代码示例仅列举规则引擎已支持的所有匹配条件和配置项,您可以根据需要自行更改传参
查询规则引擎配置
您可以参考API文档获取参数的详细信息:查询规则引擎配置
Python
1def test_get_site_page_rules(eo_client):
2 """
3 get the rule engine config
4 """
5 result = eo_client.get_site_config_items(
6 site='test-sdk-eo.baidu.com',
7 keys=['pageRules'])
8 print(result)
评价此篇文章
