设置规则引擎配置
更新时间:2026-06-18
接口
本接口用于设置规则引擎配置,其中一部分配置项与站点全局配置项的配置方式相同,您可参考站点全局配置文档进行配置。
请求接口
| 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 "offlineMode": "OFF" // 此处可添加匹配类型支持的配置项
127 },
128 "status": "ON"
129 }
130 ]
131}
响应示例
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}
评价此篇文章
