规则引擎配置
更新时间:2026-09-08
设置规则引擎配置
您可以根据API文档获取您想要设置的规则引擎配置项的详细参数信息。
PHP
1$client = new EoClient($EO_CONFIG);
2$pageRules = array(
3'pageRules' => array(
4 array(
5 'name' => '示例',
6 'rules' => array(
7 // ---- 规则组1(AND:匹配条件需同时满足) ----
8 array(
9 array(
10 'matchFrom' => 'path',
11 'operator' => 'inValues',
12 'values' => array('/test'),
13 'ignoreCase' => true, // 忽略大小写
14 ),
15 array(
16 'matchFrom' => 'directory',
17 'operator' => 'inValues',
18 'values' => array('/test/'),
19 ),
20 array(
21 'matchFrom' => 'arg',
22 'operator' => 'inValues',
23 'matchKey' => 'test',
24 'values' => array('abc'),
25 ),
26 array(
27 'matchFrom' => 'suffix',
28 'operator' => 'inValues',
29 'values' => array('jpg'),
30 ),
31 array(
32 'matchFrom' => 'header',
33 'operator' => 'inValues',
34 'matchKey' => 'user-agent',
35 'values' => array('test'),
36 ),
37 array(
38 'matchFrom' => 'fullUrl',
39 'operator' => 'inValues',
40 'values' => array('/test/test.txt'),
41 ),
42 array(
43 'matchFrom' => 'basename',
44 'operator' => 'inValues',
45 'values' => array('test.mp4'),
46 ),
47 array(
48 'matchFrom' => 'remoteGeos',
49 'operator' => 'inValues',
50 'values' => array(
51 array('pro' => 'beijing'), // 中国内地用此项
52 array('cty' => 'bt'), // 其他国家用此项
53 ),
54 ),
55 array(
56 'matchFrom' => 'remoteAddrs',
57 'operator' => 'inValues',
58 'values' => array(
59 '1.2.3.4', // IP 地址
60 '172.16.0.0/12', // IP 段
61 ),
62 ),
63 array(
64 'matchFrom' => 'remoteIsp',
65 'operator' => 'inValues',
66 'values' => 'cm|un|ct',
67 ),
68 array(
69 'matchFrom' => 'method',
70 'operator' => 'inValues',
71 'values' => array('GET', 'POST'),
72 ),
73 array(
74 'matchFrom' => 'cookie',
75 'operator' => 'inValues',
76 'matchKey' => 'test',
77 'values' => array('abc'),
78 ),
79 array(
80 'matchFrom' => 'host',
81 'operator' => 'inValues',
82 'values' => array('1.test.com'),
83 ),
84 ),
85 // ---- 规则组2(OR:任一满足即可;与规则组1为"或"关系) ----
86 array(
87 array(
88 'matchFrom' => 'path',
89 'operator' => 'regex', // 正则匹配
90 'values' => '^/example/test[123]/$',
91 ),
92 array(
93 'matchFrom' => 'arg',
94 'operator' => 'exists', // 存在匹配
95 'matchKey' => 'test',
96 ),
97 ),
98 ),
99 'config' => array(
100 // 节点缓存
101 'cacheTtl' => array(
102 array(
103 'value' => '/',
104 'weight' => 100,
105 'override_origin' => false,
106 'ttl' => 0,
107 'type' => 'path',
108 ),
109 ),
110 // 自定义 cache key
111 'cacheKey' => array(
112 'query' => false,
113 'ignore_case' => true,
114 'include_args' => array('a', 'b'),
115 ),
116 // 浏览器缓存
117 'clientCacheTtl' => array(
118 'mode' => 'custom',
119 'ttl' => 150,
120 ),
121 // 离线模式
122 'offlineMode' => 'OFF',
123 // 状态码缓存
124 'cacheCodeTtl' => array(
125 array(
126 'value' => '404',
127 'weight' => 100,
128 'overrideOrigin' => true,
129 'ttl' => 10,
130 'type' => 'code',
131 ),
132 array(
133 'value' => '400',
134 'weight' => 100,
135 'overrideOrigin' => true,
136 'ttl' => 10,
137 'type' => 'code',
138 ),
139 ),
140 // 忽略客户端刷新
141 'refreshRevalidate' => array(
142 'enabled' => true,
143 ),
144 // 强制 HTTPS
145 'httpToHttpsEnabled' => 'ON',
146 'httpToHttpsCode' => '302',
147 // HSTS
148 'hsts' => array(
149 'maxAge' => -1,
150 'includeSubDomains' => false,
151 'preload' => false,
152 ),
153 // SSL/TLS 安全配置
154 'sslProtocols' => array(
155 'TLSv1.0',
156 'TLSv1.1',
157 'TLSv1.2',
158 'TLSv1.3',
159 ),
160 'sslMode' => 'custom',
161 'sslCipherList' => 'TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256',
162 // OCSP Stapling
163 'ocsp' => 'ON',
164 // 智能加速
165 'isa' => 'ON',
166 // HTTP/2
167 'http2Disable' => 'OFF',
168 // HTTP/3
169 'http3' => array(
170 'enable' => false,
171 ),
172 // WebSocket
173 'webSocket' => array(
174 'enabled' => true,
175 'timeout' => 10,
176 ),
177 // HTTP/2 回源
178 'http2Origin' => 'ON',
179 // 最大上传大小
180 'clientMaxBodySize' => '1026',
181 // 页面压缩
182 'compress' => 'ON',
183 'compressMethodArray' => array('gzip', 'br'),
184 // HTTP 节点响应头
185 'clientResponse' => array(
186 'addHeaders' => array(
187 'test' => '${uri}',
188 'test2' => '11',
189 ),
190 'removeHeaders' => array(
191 'Content-Type' => '',
192 ),
193 ),
194 // HTTP 回源请求头
195 'originRequest' => array(
196 'addHeaders' => array(
197 'test' => '${uri}',
198 'test2' => '11',
199 ),
200 'removeHeaders' => array(
201 'Content-Type' => '',
202 ),
203 ),
204 // 源站修改(originConfig 与 originPool 不能同时设置,此处仅设置 originConfig)
205 'originConfig' => array(
206 array(
207 'addr' => '1.1.1.1',
208 'httpPort' => 80,
209 'type' => 'IP',
210 'upstreamProtocol' => 'http',
211 'host' => 'test.eo.com',
212 ),
213 ),
214 // 回源超时时间
215 'originTimeout' => array(
216 'loadTimeout' => 10,
217 'connectTimeout' => 5,
218 ),
219 // 回源 301/302 跟随
220 'originRedirectOptions' => array(
221 'enableRedirectFollow' => 'ON',
222 'maxRedirectFollowCount' => 2,
223 ),
224 // 回源 range
225 'originOptions' => array(
226 'range' => 'force_all',
227 'partSize' => '512k',
228 ),
229 // 用户 IP 获取
230 'realIp' => array(
231 'enabled' => true,
232 'name' => 'True-Client-Ip',
233 ),
234 // 自定义错误页面
235 'errorPage' => array(
236 array(
237 'code' => 400,
238 'url' => 'http://test.eo.com/400.html',
239 ),
240 array(
241 'code' => 403,
242 'url' => 'http://test.eo.com/403.html',
243 ),
244 ),
245 // 单链接限速
246 'trafficLimit' => array(
247 'enable' => true,
248 'limitRate' => 1,
249 'limitStartHour' => 10,
250 'limitEndHour' => 19,
251 'limitRateUnit' => 'k',
252 ),
253 // URL 鉴权
254 'antiHotLink' => array(
255 'antiType' => 'typeA',
256 'secretKey' => 'xxx',
257 'newsecretKey' => 'xxx',
258 'timeout' => 1800,
259 'timestampFormat' => 'dec',
260 'authArg' => 'auth_key',
261 ),
262 // 回源请求参数
263 'originArg' => array(
264 'ignore' => true,
265 'args' => array(),
266 ),
267 // 访问 URL 重定向
268 'urlRules' => array(
269 array(
270 'scheme' => 'http',
271 'host' => 'test.eo.com',
272 'status' => 302,
273 'query' => 'OFF',
274 'dstPath' => '/test/1.txt',
275 ),
276 ),
277 ),
278 'status' => 'ON',
279 ),
280 ),
281);
282
283$resp = $this->client->setSiteConfig('test-sdk-eo.baidu.com', $pageRules);
284
285print_r($resp);
查询规则引擎配置
PHP
1$client = new EoClient($$EO_CONFIG);
2$resp = $client->getSiteConfig('test-sdk-eo.baidu.com');
3
4// 规则引擎配置
5print_r($resp->pageRules);
评价此篇文章
