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