You need to enable JavaScript to run this app.
文档中心
内容分发网络

内容分发网络

复制全文
下载 pdf
UpdateCdnConfig - 修改加速域名配置
规则引擎配置
复制全文
下载 pdf
规则引擎配置

更新域名的规则引擎配置。

注意

规则引擎配置的更新方式是全量覆盖更新。在更新规则引擎配置时,如果 Rules 未包含某条现有规则的配置,该规则会在 API 调用时被删除。同样,如果一条规则中的某个已有配置没有被指定,则该配置也会被移除。您可以调用 DescribeCdnConfig 获取当前所有规则的配置。

使用限制

节流限制:您每秒最多可以提交 20 个 API 请求。

请求说明

  • 请求方式:POST
  • 请求地址:https://cdn.volcengineapi.com/?Action=UpdateCdnConfig&Version=2021-03-01

请求参数

Query

参数名称
数据类型
是否必选
参数说明
Action
String
是
接口名称。当前 API 的名称为 UpdateCdnConfig。
Version
String
是
接口版本。当前 API 的版本为 2021-03-01。

Body

参数名称
数据类型
是否必选
参数说明
示例
Domain
String
是
表示需要配置的域名。
www.example.com
RuleEngine
Object
否
表示规则引擎的配置。

各 Stage 下 Action 的参数配置

Stage 为 client_request

行为(Action)配置参数示例

redirect_request

  • source_path:原始路径,通过正则表达式匹配。

  • status_code:重定向状态码,取值有 301、302、303、307、308。

  • protocol:重定向协议。取值有 follow_client、http、https。

  • target_host:目标站点的域名或 IP 地址,端口可选。

  • target_path:目标路径,支持指定$n 捕获原始路径的组。

  • target_query_action:对用户请求 URL 中查询参数的处理方式,取值有 include_part、include_all、exclude_part、exclude_all。

  • target_query_values:需要包含或移除的参数。适用于 target_query_action 是 include_part 或 exclude_part 的情况。

redirect_request
1.66KB

redirect_protocol

  • status_code:重定向状态码,取值有 301、302、303、307、308。

  • protocol:重定向协议。取值有 http、https。

redirect_protocol
781.00Bytes

allow_access

  • effective_scope:生效范围,取值有 rule_engine、method_denied_rule、area_access_rule、request_block_rule。生效范围内的访问控制规则不再拦截符合规则引擎条件的请求。
allow_access.json
729.00Bytes

download_speed_limit

  • limit_type:传输速度上限。取值有 normal、dynamic_limit。

  • rate:传输速度上限。

  • query_name:限速参数的名称。适用于 limit_type 是 dynamic_limit 的情况。

  • dynamic_rate_unit:限速参数所指示的速度的单位。取值有 KB/s、B/s、MB/s。适用于 limit_type 是 dynamic_limit 的情况。

  • rate_unit:速度单位。取值有 KB/s、B/s、MB/s。

  • after_size:限速规则生效前的不限速数据量。

  • after_size_unit:数据量单位。取值有 B、KB、MB。

download_speed_limit.json
1.85KB

request_header

  • action: 请求头操作,取值有 set、delete。

  • header_name:头部名称。

  • header_value:头部值,适用于 action 是 set 的情况。

request_header
1.50KB

deny_access

  • status_code:CDN 响应状态码,范围是 100-599。
deny_access
552.00Bytes

url_auth

  • auth_type:鉴权类型,取值有 type_a、type_b、type_c、type_d、type_e

Type A 配置参数

  • master_secret_key:主密钥。

  • backup_secret_key:备密钥。

  • sign_name:签名参数的名称。

  • duration:签名的有效时长,单位是秒。

  • time_format:时间戳的格式,取值为 dec。

  • algorithm:鉴权算法,取值有:md5、sha256。

  • origin_keep_auth_query:是否在回源请求以及缓存键中均包含签名参数,取值有 true、false。

  • rewrite_m3u8:是否启用 "M3U8 改写",取值有 true、false。

  • keep_slice_query:是否保留视频分片 URI 中的查询参数,取值有 true、false。

  • m3u8_keep_query:是否在视频分片 URI 中添加用户请求 URL 中的非签名参数,取值有 true、false。

  • rewrite_m3u8_tag:额外需要进行 URI 改写的标签列表。

Type B 配置参数

  • master_secret_key、backup_secret_key、duration、algorithm、rewrite_m3u8、keep_slice_query、m3u8_keep_query、rewrite_m3u8_tag

  • time_format:取值有:dec、hex、basicFormat2m。basicFormat2m 表示的格式是 YYYYMMDDHHMM。

Type C 配置参数

  • master_secret_key、backup_secret_key、duration、algorithm、rewrite_m3u8、keep_slice_query、m3u8_keep_query、rewrite_m3u8_tag

  • time_format:取值为 hex。

Type D 配置参数

  • master_secret_key、backup_secret_key、sign_name、time_name、duration、algorithm、origin_keep_auth_query、rewrite_m3u8、keep_slice_query、m3u8_keep_query、rewrite_m3u8_tag

  • time_format:取值有:dec、hex。

  • time_name:时间戳参数的名称。

Type E 配置参数

  • master_secret_key、backup_secret_key、sign_name、time_name、duration、algorithm、rewrite_m3u8、keep_slice_query、m3u8_keep_query、rewrite_m3u8_tag

  • time_format:取值有:dec、hex。

  • custom_headers:额外参与签名计算的自定义请求头,最多 50 个。

  • custom_queries:额外参与签名计算的查询参数,最多 50 个。

  • signature_rules:参数签名计算的对象顺序。signature_rules 中可以包含 referer、origin、secret_key、domain、uri、ip、ua、time_name 以及您在 custom_headers 和 custom_queries 中定义的请求头和查询参数。这里,uri 表示请求 URL 中的路径,不包含查询参数。time_name 表示时间戳。

type-a.json
3.19KB
type_b.json
2.76KB
type_c.json
2.76KB
type_d.json
3.40KB
type-e.json
4.30KB

Stage 为 cache

行为(Action)配置参数示例

cache_key

Dimension 为 query_string 时,表示对请求 URL 中查询参数的处理方式。缓存键默认包含所有查询参数,有以下配置参数:

  • query_action:包含的查询参数,取值有 include_part、include_all、exclude_part、exclude_all。

  • query_names:需要包含或移除的参数。适用于 target_query_action 是 include_part 或 exclude_part 的情况。

  • ignore_case:查询参数名称是否是大小写敏感的。


Dimension 为 request_header 时,表示对请求中头部的处理方式。缓存键默认不包含任何头部,有以下配置参数:

  • header_names:包含的头部列表。

  • ignore_case:头部名称是否是大小写敏感的,取值必须为 true。


Dimension 为 cookie 时,表示对请求中 Cookie 的处理方式。缓存键默认不包含任何 cookie,有以下配置参数:

  • cookie_action:对用户请求中 Cookie 的处理方式,取值有 include_part、include_all、exclude_part、exclude_all。

  • cookie_names:需要包含的 Cookie 列表,列表中是这些 Cookie 的 Key。

  • ignore_case:Cookie key 是否是大小写敏感的。


Dimension 为 request_path 时,表示是否改写原始路径,默认不改写原始路径,有以下配置参数:

  • source_path:原始路径,通过正则表达式匹配。

  • target_path:改写后的路径,支持指定$n 捕获原始路径的组。


Dimension 为 path_ignore_case 时,表示缓存键中的路径是否区分大小写。默认是大小写不敏感,有以下配置参数:

  • ignore_case:缓存键中的路径是否是大小写敏感的。

cache_key
4.36KB

compression

  • methods:压缩算法,取值有 br、gzip。

  • min_file_size:文件最小尺寸。小于该尺寸的文件不压缩。

  • min_file_size_unit:尺寸单位。取值有 KB、MB。

  • format:文件类型的配置,CDN 仅压缩指定类型的文件。取值有 default、customize。default 表示content_types 列表中的所有类型。

  • content_types:指定的文件类型、适用于 format 是 customize 的情况。取值有:text/html、text/plain、text/xml、text/css、application/javascript、application/x-javascript、application/rss+xml、application/json、image/tiff、text/javascript、image/svg+xml、application/xml、text/plain; charset=utf-8。

compression
1.48KB

video_drag

  • switch:是否启用视频拖拽。
video_drag
537.00Bytes

cache_time

  • ttl:缓存时长,适用于 cache_policy为 default 的情况。

  • ttl_unit:缓存时长的单位,取值有 sec、min、hour、day。适用于 cache_policy为 default 的情况。

  • cache_policy:缓存策略,取值有 default、origin_first、no_cache。

  • force_cache:是否开启 "强制缓存"。适用于 cache_policy为 default 的情况。

  • replenish:是否开启 "补充缓存"。适用于 cache_policy为 origin_first的情况。

  • set_cookie_no_cache:是否缓存包含 Set-Cookie 头部的源站响应。

cache_time
1.39KB

Stage 为 client_response

行为(Action)配置参数配置参数

response_header

  • action: CDN 响应用户请求时对响应头的操作,取值有 set、delete。

  • header_name:头部名称。

  • header_value:头部值,适用于 action 是 set 的情况。

response_header
1009.00Bytes

browser_cache

  • cache_policy:缓存策略,取值有 cache、origin_first、no_cache。

当 cache_policy 为 cache 时,您还需要设置:

  • ttl:缓存时长,最长 10 年。

  • ttl_unit:时长单位,取值有 sec、min、hour、day。

browser_cache.json
984.00Bytes

http_code

  • status_code:自定义 CDN 响应状态码,取值范围为 100-999。
http_code.json
549.00Bytes

custom_page

  • page_mode:取值必须为 redirection,表示页面重定向。

  • status_code:CDN 响应状态码,取值有 301、302、303、307、308。

  • location:重定向 URL。

custom_page.json
1012.00Bytes

Stage 为 origin_request

行为(Action)配置参数示例

origin_range

  • switch:是否启用回源 Range。

  • range_type:分片类型,取值只能为 fixed,表示固定分片。

  • range_size:分片大小。

    • 如果 unit 是 KB,range_size 只能是 512。

    • 如果 unit 是 MB,range_size 的取值范围是 1-40。

  • unit:分片的单位,取值有 KB、MB。

origin_range.json
1.17KB

origin_follow

  • switch:是否启用回源重定向跟随。
origin_follow
552.00Bytes

origin_tcp_timeout

  • connect_timeout:TCP 建连的超时时长,默认值是 2。

  • connect_timeout_unit:超时时长的单位,取值只能是 sec。

origin_tcp_timeout
796.00Bytes

origin_http_timeout

  • connect_timeout:HTTP 请求的超时时长,默认值是 60。

  • connect_timeout_unit:超时时长的单位,取值只能是 sec。

origin_http_timeout.json
792.00Bytes

origin_rewrite

  • action:改写类型,有以下取值:

    • path_rewrite:路径改写,不包含查询参数。

    • url_rewrite:路径改写,包含查询参数。

  • source_path:改写前的路径,是一个正则表达式。

  • target_path:改写后的路径,是一个正则表达式。

  • mode:改写后的行为,取值只能为 break,表示当前规则完成改写后,停止继续匹配后续改写规则。

origin_rewrite.json
2.15KB

origin_sni

  • domain:自定义的 SNI 域名。
origin_sni.json
557.00Bytes

origin_protocol

  • origin_protocol:回源请求使用的协议,取值有 follow_client、http、https。
origin_protocol.json
574.00Bytes

origin_request_header

  • action: CDN 响应用户请求时对响应头的操作,取值有 set、delete。

  • header_name:头部名称。

  • header_value:头部值,适用于 action 是 set 的情况。

origin_request_header.json
1.47KB

origin_host

  • host:回源请求中的 Host 头部值。
origin_host.json
557.00Bytes

各匹配对象的输入要求

匹配对象IgnoreCase可指定的 OperatorName 输入要求Value 输入要求示例值
always不适用不适用不适用不适用

path

适用

equal not_equal

不适用

  • 必须以 / 开头。

  • 总数不能超过 100 个,总长度不能超过 300 个字符。

  • 不能包含空格、百分号(%)。

["/www/img/myimage.png", "/docs/file"]

prefix_match prefix_not_match

  • 必须以 / 开头。

  • 总数不能超过 100 个,总长度不能超过 300 个字符。

  • 不能包含空格、百分号(%)

["/www", "/docs/f"]

suffix_match suffix_not_match

  • 总数不能超过 100 个,总长度不能超过 300 个字符。

  • 不能包含空格、百分号(%)。

  • 不能以句点(.)开头。

["png","docx"]

regex_match regex_not_match

  • 总数不能超过 50 个,总长度不能超过 300 个字符。

  • 不能包含空格、百分号(%)。

["^/a{1,2}(.*)g$"]

path_and_param适用与 path 相同不适用与 path 相同。

url

适用

equal not_equal

不适用

  • 必须以 http:// 或者 https:// 开头。

  • 总数不能超过 100 个,总长度不能超过 300 个字符。

  • 不能包含空格、百分号(%)。

["https://www.example.com/www/img/myimage.png","https://www.example.com/docs/file"]

prefix_match prefix_not_match

  • 必须以 http:// 或者 https:// 开头。

  • 总数不能超过 100 个,总长度不能超过 300 个字符。

  • 不能包含空格、百分号(%)。

["https://www.example.com/www", "https://www.example.com/docs/f"]

suffix_match suffix_not_match

  • 总数不能超过 100 个,总长度不能超过 300 个字符。

  • 不能包含空格、百分号(%)。

["png","docx"]

regex_match regex_not_match

  • 总数不能超过 50 个,总长度不能超过 300 个字符。

  • 不能包含空格、百分号(%)。

["^/a{1,2}(.*)g$"]

http_referer

适用

equal not_equal

不适用

  • 总数不能超过 100 个。

  • 单个条目的长度不能超过 200 个字符。

["https://www.example.com/image.png", "a.example.com","*.exampe.net","203.0.113.8"]

exist not_exist不适用

regex_match regex_not_match

  • 总数不能超过 50 个。

  • 单个条目的长度不能超过 200 个字符。

["^/a{1,2}(.*)g$"]

client_ip

不适用

match not_match

不适用

  • 支持 IP 地址和 CIDR 网段。

  • 支持 IPv4 地址和 IPv6 地址。

  • 总数不能超过 100 个,

["203.0.113.8","203.0.113.9"]

http_origin适用与 http_referer 相同。不适用与 http_referer 相同。

http_ua

适用

与 http_referer 相同。

不适用

与 http_referer 相同。

request_header

适用

与 http_referer 相同。

  • 不能包含汉字、下划线(_)、空格、双引号(")、冒号(:)。

  • 长度不能超过 100 个字符。

与 http_referer 相同。

Name
myheader

Value
["value1","value2"]

client_area

不适用

match not_match

不适用

  • 包含最多 30 个国家或地区的 Alpha-3 代码。Alpha-3 代码可以调用 DescribeCdnRegionAndIsp 获取。

["PNG","FSM","FSM"]

http_method

不适用

equal not_equal

不适用

  • 包含以下一个或者多个值:post、head、get、put、options、delete、connect、patch。

["post","options"]

request_time

不适用

match not_match

weekday:每一周中的某些天。

  • 包含以下一个或者多个值:mon、tue、wed、thur、fri、sat、sun。

["mon","fri"]

period:某个任意时间段。开始时间和结束时间精确到秒。["2025-05-07 14:21:21", "2025-06-13 14:21:24"]
everyday:一天中的某个时间段。["02:02:02","06:04:04"]
protocol不适用equal not_equal不适用指定 http 或者 https。["http"]
client_cert_info适用match not_matchcommon_name:证书主题中的通用名称(Common Name)。总数不能超过 100 个,每个长度不能超过 64 个字符,支持以通配符 * 开头和结尾。["www.example.com"]
serial_number:证书序列号。["03A7F2C91B4E6D8A"]
country_name:证书主体所属国家或地区的代码。["CN"]
locality_name:证书主体所在的城市或地区。["Beijing"]
organization_name:证书主体所属组织或公司名称。["Example Co., Ltd."]
organizational_unit_name:证书主体所属的组织单位或部门名称。["IT Department"]

response_header

适用

与 http_referer 相同。

  • 不能包含汉字、下划线(_)、空格、双引号(")、冒号(:)。

  • 长度不能超过 100 个字符。

与 http_referer 相同。

Name
myheader

Value
["value1","value2"]

http_code

不适用

match not_match

不适用

  • 包含最多 30 个状态码。

  • 状态码的范围是 100-599。

  • 支持指定 2xx、3xx 等。

["405","5xx"]

返回参数

由于该 API 没有响应参数,响应正文只有包含请求元数据的 ResponseMetadata 结构体,没有 Result 结构体。

请求示例 1

POST https://cdn.volcengineapi.com/?Action=UpdateCdnConfig&Version=2021-03-01
{
    "Domain": "www.example.com",
    "RuleEngine": {
        "Switch": true,
        "Rules": [
            {
                "Id": "rule-f3c165",
                "Name": "Rule 1",
                "Rule": "{\"IfBlock\":{\"SubRules\":[],\"Actions\":[{\"Action\":\"origin_tcp_timeout\",\"Stage\":\"origin_request\",\"Phase\":2,\"Module\":2,\"Groups\":[{\"Dimension\":\"origin_tcp_timeout\",\"GroupParameters\":[{\"Parameters\":[{\"Name\":\"connect_timeout\",\"Values\":[\"30\"]},{\"Name\":\"connect_timeout_unit\",\"Values\":[\"sec\"]}]}]}]}],\"Condition\":{\"IsGroup\":true,\"Connective\":\"and\",\"ConditionGroups\":[{\"IsGroup\":true,\"Connective\":\"and\",\"ConditionGroups\":[{\"IsGroup\":false,\"Condition\":{\"Object\":\"always\"}}]}]}}}",
                "Switch": true
            }
        ]
    }
}

请求示例 2

本示例重点展示 Condition 的配置。

说明

要调用本示例,请先处理 Rule 结构体中的参数配置。参见 Rule 参数的说明。

POST https://cdn.volcengineapi.com/?Action=UpdateCdnConfig&Version=2021-03-01
{
    "Domain": "www.example.com",
    "RuleEngine": {
        "Switch": true,
        "Rules": [
            {
                "Id": "rule-f3c165",
                "Name": "Rule 1",
                "Switch": true,
                "Rule": [
                    {
                        "Desc": "myDesc",
                        "IfBlock": {
                            "SubRules": [
                                {
                                    "Desc": "Sub-rule1",
                                    "IfBlock": {
                                        "SubRules": [],
                                        "Actions": [
                                            {
                                                "Action": "response_header",
                                                "Stage": "client_response",
                                                "Phase": 6,
                                                "Module": 1,
                                                "Groups": [
                                                    {
                                                        "Dimension": "response_header",
                                                        "GroupParameters": [
                                                            {
                                                                "Parameters": [
                                                                    {
                                                                        "Name": "action",
                                                                        "Values": [
                                                                            "set"
                                                                        ]
                                                                    },
                                                                    {
                                                                        "Name": "header_name",
                                                                        "Values": [
                                                                            "myheader2"
                                                                        ]
                                                                    },
                                                                    {
                                                                        "Name": "header_value",
                                                                        "Values": [
                                                                            "myheadervalue"
                                                                        ]
                                                                    }
                                                                ]
                                                            }
                                                        ]
                                                    }
                                                ]
                                            }
                                        ],
                                        "Condition": {
                                            "IsGroup": true,
                                            "Connective": "and",
                                            "ConditionGroups": [
                                                {
                                                    "IsGroup": true,
                                                    "Connective": "and",
                                                    "ConditionGroups": [
                                                        {
                                                            "IsGroup": false,
                                                            "Condition": {
                                                                "Object": "always"
                                                            }
                                                        },
                                                        {
                                                            "IsGroup": false,
                                                            "Condition": {
                                                                "Object": "path",
                                                                "Operator": "suffix_match",
                                                                "IgnoreCase": true,
                                                                "Value": [
                                                                    "param=value"
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    },
                                    "ElseBlock": {
                                        "SubRules": [],
                                        "Actions": [
                                            {
                                                "Action": "response_header",
                                                "Stage": "client_response",
                                                "Phase": 6,
                                                "Module": 1,
                                                "Groups": [
                                                    {
                                                        "Dimension": "response_header",
                                                        "GroupParameters": [
                                                            {
                                                                "Parameters": [
                                                                    {
                                                                        "Name": "action",
                                                                        "Values": [
                                                                            "delete"
                                                                        ]
                                                                    },
                                                                    {
                                                                        "Name": "header_name",
                                                                        "Values": [
                                                                            "myheader3"
                                                                        ]
                                                                    }
                                                                ]
                                                            }
                                                        ]
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                }
                            ],
                            "Actions": [
                                {
                                    "Action": "response_header",
                                    "Stage": "client_response",
                                    "Phase": 6,
                                    "Module": 1,
                                    "Groups": [
                                        {
                                            "Dimension": "response_header",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "action",
                                                            "Values": [
                                                                "set"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "header_name",
                                                            "Values": [
                                                                "myheader"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "header_value",
                                                            "Values": [
                                                                "myheadervalue"
                                                            ]
                                                        }
                                                    ]
                                                },
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "action",
                                                            "Values": [
                                                                "delete"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "header_name",
                                                            "Values": [
                                                                "myheader1"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ],
                            "Condition": {
                                "IsGroup": true,
                                "Connective": "and",
                                "ConditionGroups": [
                                    {
                                        "IsGroup": true,
                                        "Connective": "and",
                                        "ConditionGroups": [
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "always"
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "path",
                                                    "Operator": "suffix_match",
                                                    "IgnoreCase": true,
                                                    "Value": [
                                                        "jpg",
                                                        "png"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "path_and_param",
                                                    "Operator": "prefix_match",
                                                    "IgnoreCase": true,
                                                    "Value": [
                                                        "/docs1/",
                                                        "/docs2/"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "url",
                                                    "Operator": "equal",
                                                    "IgnoreCase": true,
                                                    "Value": [
                                                        "https://www.example.com/abc/file"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "query_string",
                                                    "Name": "myparam",
                                                    "Operator": "equal",
                                                    "IgnoreCase": true,
                                                    "Value": [
                                                        "myvalue",
                                                        "myvalue2"
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    {
                                        "IsGroup": true,
                                        "Connective": "and",
                                        "ConditionGroups": [
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "http_referer",
                                                    "Operator": "not_equal",
                                                    "IgnoreCase": true,
                                                    "Value": [
                                                        "myreferer1",
                                                        "myreferere2"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "client_ip",
                                                    "Operator": "match",
                                                    "Value": [
                                                        "203.0.113.8",
                                                        "203.0.113.9"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "http_origin",
                                                    "Operator": "exist"
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "http_ua",
                                                    "Operator": "not_exist"
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "request_header",
                                                    "Name": "myhttpheader",
                                                    "Operator": "equal",
                                                    "IgnoreCase": true,
                                                    "Value": [
                                                        "abc",
                                                        "cde"
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    {
                                        "IsGroup": true,
                                        "Connective": "and",
                                        "ConditionGroups": [
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "client_area",
                                                    "Operator": "not_match",
                                                    "Value": [
                                                        "PNG",
                                                        "FSM"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "http_method",
                                                    "Operator": "equal",
                                                    "Value": [
                                                        "post",
                                                        "head",
                                                        "get",
                                                        "put",
                                                        "options",
                                                        "delete",
                                                        "connect",
                                                        "patch"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "request_time",
                                                    "Name": "everyday",
                                                    "Operator": "match",
                                                    "TimeZone": "+0800",
                                                    "Value": [
                                                        "02:02:02",
                                                        "06:04:04"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "request_time",
                                                    "Name": "weekday",
                                                    "Operator": "not_match",
                                                    "TimeZone": "+0800",
                                                    "Value": [
                                                        "mon",
                                                        "tue",
                                                        "wed",
                                                        "thur",
                                                        "fri",
                                                        "sat",
                                                        "sun"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "request_time",
                                                    "Name": "period",
                                                    "Operator": "not_match",
                                                    "TimeZone": "+0800",
                                                    "Value": [
                                                        "2025-05-07 14:21:21",
                                                        "2025-06-13 14:21:24"
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    {
                                        "IsGroup": true,
                                        "Connective": "and",
                                        "ConditionGroups": [
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "protocol",
                                                    "Operator": "equal",
                                                    "Value": [
                                                        "http"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "response_header",
                                                    "Name": "myresponseheader",
                                                    "Operator": "not_equal",
                                                    "IgnoreCase": true,
                                                    "Value": [
                                                        "resheader1",
                                                        "resheader2"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "http_code",
                                                    "Operator": "match",
                                                    "Value": [
                                                        "400",
                                                        "500"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "path",
                                                    "Operator": "prefix_not_match",
                                                    "IgnoreCase": true,
                                                    "Value": [
                                                        "/abc/"
                                                    ]
                                                }
                                            },
                                            {
                                                "IsGroup": false,
                                                "Condition": {
                                                    "Object": "path",
                                                    "Operator": "suffix_not_match",
                                                    "IgnoreCase": true,
                                                    "Value": [
                                                        "/def/"
                                                    ]
                                                }
                                            }
                                        ]
                                    }
                                ]
                            }
                        },
                        "ElseBlock": {
                            "SubRules": [
                                {
                                    "Desc": "SubRule1",
                                    "IfBlock": {
                                        "SubRules": [],
                                        "Actions": [
                                            {
                                                "Action": "response_header",
                                                "Stage": "client_response",
                                                "Phase": 6,
                                                "Module": 1,
                                                "Groups": [
                                                    {
                                                        "Dimension": "response_header",
                                                        "GroupParameters": [
                                                            {
                                                                "Parameters": [
                                                                    {
                                                                        "Name": "action",
                                                                        "Values": [
                                                                            "set"
                                                                        ]
                                                                    },
                                                                    {
                                                                        "Name": "header_name",
                                                                        "Values": [
                                                                            "myheader6"
                                                                        ]
                                                                    },
                                                                    {
                                                                        "Name": "header_value",
                                                                        "Values": [
                                                                            "1111"
                                                                        ]
                                                                    }
                                                                ]
                                                            }
                                                        ]
                                                    }
                                                ]
                                            }
                                        ],
                                        "Condition": {
                                            "IsGroup": true,
                                            "Connective": "and",
                                            "ConditionGroups": [
                                                {
                                                    "IsGroup": true,
                                                    "Connective": "and",
                                                    "ConditionGroups": [
                                                        {
                                                            "IsGroup": false,
                                                            "Condition": {
                                                                "Object": "http_referer",
                                                                "Operator": "exist"
                                                            }
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    },
                                    "ElseBlock": {
                                        "SubRules": [],
                                        "Actions": [
                                            {
                                                "Action": "response_header",
                                                "Stage": "client_response",
                                                "Phase": 6,
                                                "Module": 1,
                                                "Groups": [
                                                    {
                                                        "Dimension": "response_header",
                                                        "GroupParameters": [
                                                            {
                                                                "Parameters": [
                                                                    {
                                                                        "Name": "action",
                                                                        "Values": [
                                                                            "delete"
                                                                        ]
                                                                    },
                                                                    {
                                                                        "Name": "header_name",
                                                                        "Values": [
                                                                            "myheader7"
                                                                        ]
                                                                    }
                                                                ]
                                                            }
                                                        ]
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                }
                            ],
                            "Actions": [
                                {
                                    "Action": "response_header",
                                    "Stage": "client_response",
                                    "Phase": 6,
                                    "Module": 1,
                                    "Groups": [
                                        {
                                            "Dimension": "response_header",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "action",
                                                            "Values": [
                                                                "delete"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "header_name",
                                                            "Values": [
                                                                "MyHeader"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    }
                ]
            }
        ]
    }
}

请求示例 3

本示例重点展示 Action 的配置。

说明

要调用本示例,请先处理 Rule 结构体中的参数配置。参见 Rule 参数的说明。

POST https://cdn.volcengineapi.com/?Action=UpdateCdnConfig&Version=2021-03-01
{
    "Domain": "www.example.com",
    "RuleEngine": {
        "Switch": true,
        "Rules": [
            {
                "Id": "rule-2e6975",
                "Name": "My Rule",
                "Switch": true,
                "Rule": [
                    {
                        "Desc": "myDesc",
                        "IfBlock": {
                            "Condition": {
                                "IsGroup": true,
                                "Connective": "and",
                                "ConditionGroups": [
                                    {
                                        "IsGroup": true,
                                        "Connective": "and",
                                        "ConditionGroups": [
                                            {
                                                "IsGroup": false,
                                                "Connective": "and",
                                                "Condition": {
                                                    "Object": "always"
                                                }
                                            }
                                        ]
                                    }
                                ]
                            },
                            "Actions": [
                                {
                                    "Action": "redirect_request",
                                    "Stage": "client_request",
                                    "Phase": 1,
                                    "Module": 1,
                                    "Groups": [
                                        {
                                            "Dimension": "redirect_request",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "source_path",
                                                            "Values": [
                                                                "^/docs/file1$"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "status_code",
                                                            "Values": [
                                                                "301"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "protocol",
                                                            "Values": [
                                                                "follow_client"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "target_host",
                                                            "Values": [
                                                                "www.example.com"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "target_path",
                                                            "Values": [
                                                                "^/cos1/file2$"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "target_query_action",
                                                            "Values": [
                                                                "include_all"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "allow_access",
                                    "Stage": "client_request",
                                    "Phase": 1,
                                    "Module": 1,
                                    "Groups": [
                                        {
                                            "Dimension": "allow_access",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "effective_scope",
                                                            "Values": [
                                                                "rule_engine",
                                                                "method_denied_rule",
                                                                "area_access_rule",
                                                                "request_block_rule"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "download_speed_limit",
                                    "Stage": "client_request",
                                    "Phase": 1,
                                    "Module": 1,
                                    "Groups": [
                                        {
                                            "Dimension": "download_speed_limit",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "rate",
                                                            "Values": [
                                                                "100"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "rate_unit",
                                                            "Values": [
                                                                "B/s"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "after_size",
                                                            "Values": [
                                                                "15"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "after_size_unit",
                                                            "Values": [
                                                                "MB"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "request_header",
                                    "Stage": "client_request",
                                    "Phase": 1,
                                    "Module": 1,
                                    "Groups": [
                                        {
                                            "Dimension": "request_header",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "action",
                                                            "Values": [
                                                                "set"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "header_name",
                                                            "Values": [
                                                                "myheader"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "header_value",
                                                            "Values": [
                                                                "myvalue"
                                                            ]
                                                        }
                                                    ]
                                                },
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "action",
                                                            "Values": [
                                                                "delete"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "header_name",
                                                            "Values": [
                                                                "myheader"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "deny_access",
                                    "Stage": "client_request",
                                    "Phase": 1,
                                    "Module": 1,
                                    "Groups": [
                                        {
                                            "Dimension": "deny_access",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "status_code",
                                                            "Values": [
                                                                "465"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "cache_key",
                                    "Stage": "cache",
                                    "Phase": 5,
                                    "Module": 3,
                                    "Groups": [
                                        {
                                            "Dimension": "query_string",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "query_action",
                                                            "Values": [
                                                                "exclude_part"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "query_names",
                                                            "Values": [
                                                                "myparam1",
                                                                "myparam2"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "ignore_case",
                                                            "Values": [
                                                                "true"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "Dimension": "request_header",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "header_names",
                                                            "Values": [
                                                                "myheader",
                                                                "myheader2"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "ignore_case",
                                                            "Values": [
                                                                "true"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "Dimension": "request_path",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "source_path",
                                                            "Values": [
                                                                "^/path1/$"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "target_path",
                                                            "Values": [
                                                                "^/path2/$"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "Dimension": "path_ignore_case",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "ignore_case",
                                                            "Values": [
                                                                "true"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "compression",
                                    "Stage": "cache",
                                    "Phase": 5,
                                    "Module": 2,
                                    "Groups": [
                                        {
                                            "Dimension": "compression",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "methods",
                                                            "Values": [
                                                                "gzip",
                                                                "brotli"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "min_file_size",
                                                            "Values": [
                                                                "563"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "min_file_size_unit",
                                                            "Values": [
                                                                "KB"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "format",
                                                            "Values": [
                                                                "default"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "video_drag",
                                    "Stage": "cache",
                                    "Phase": 5,
                                    "Module": 2,
                                    "Groups": [
                                        {
                                            "Dimension": "video_drag",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "switch",
                                                            "Values": [
                                                                "true"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "cache_time",
                                    "Stage": "cache",
                                    "Phase": 5,
                                    "Module": 2,
                                    "Groups": [
                                        {
                                            "Dimension": "cache_time",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "ttl",
                                                            "Values": [
                                                                "56"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "ttl_unit",
                                                            "Values": [
                                                                "day"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "cache_policy",
                                                            "Values": [
                                                                "origin_first"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "replenish",
                                                            "Values": [
                                                                "true"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "set_cookie_no_cache",
                                                            "Values": [
                                                                "true"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "origin_range",
                                    "Stage": "origin_request",
                                    "Phase": 2,
                                    "Module": 2,
                                    "Groups": [
                                        {
                                            "Dimension": "origin_range",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "switch",
                                                            "Values": [
                                                                "true"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "range_type",
                                                            "Values": [
                                                                "fixed"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "range_size",
                                                            "Values": [
                                                                "1"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "unit",
                                                            "Values": [
                                                                "MB"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "origin_follow",
                                    "Stage": "origin_request",
                                    "Phase": 2,
                                    "Module": 2,
                                    "Groups": [
                                        {
                                            "Dimension": "origin_follow",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "switch",
                                                            "Values": [
                                                                "true"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "origin_tcp_timeout",
                                    "Stage": "origin_request",
                                    "Phase": 2,
                                    "Module": 2,
                                    "Groups": [
                                        {
                                            "Dimension": "origin_tcp_timeout",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "connect_timeout",
                                                            "Values": [
                                                                "56"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "connect_timeout_unit",
                                                            "Values": [
                                                                "sec"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "origin_http_timeout",
                                    "Stage": "origin_request",
                                    "Phase": 2,
                                    "Module": 2,
                                    "Groups": [
                                        {
                                            "Dimension": "origin_http_timeout",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "read_timeout",
                                                            "Values": [
                                                                "58"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "read_timeout_unit",
                                                            "Values": [
                                                                "sec"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "Action": "url_auth",
                                    "Stage": "client_request",
                                    "Phase": 1,
                                    "Module": 3,
                                    "Groups": [
                                        {
                                            "Dimension": "url_auth",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "auth_type",
                                                            "Values": [
                                                                "type_e"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "master_secret_key",
                                                            "Values": [
                                                                "pk123"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "backup_secret_key",
                                                            "Values": [
                                                                "bk456"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "sign_name",
                                                            "Values": [
                                                                "sign"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "time_name",
                                                            "Values": [
                                                                "ts"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "duration",
                                                            "Values": [
                                                                "600"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "time_format",
                                                            "Values": [
                                                                "hex"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "algorithm",
                                                            "Values": [
                                                                "md5"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "rewrite_m3u8",
                                                            "Values": [
                                                                "true"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "keep_slice_query",
                                                            "Values": [
                                                                "true"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "m3u8_keep_query",
                                                            "Values": [
                                                                "true"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "custom_headers",
                                                            "Values": [
                                                                "header1",
                                                                "header2"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "custom_queries",
                                                            "Values": [
                                                                "param1",
                                                                "param2"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "signature_rules",
                                                            "Values": [
                                                                "secret_key",
                                                                "domain",
                                                                "uri",
                                                                "ip",
                                                                "ua",
                                                                "referer",
                                                                "origin",
                                                                "time_name",
                                                                "header1",
                                                                "header2",
                                                                "param1",
                                                                "param2"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        },
                        "ElseBlock": {
                            "Actions": [
                                {
                                    "Action": "redirect_protocol",
                                    "Stage": "client_request",
                                    "Phase": 1,
                                    "Module": 1,
                                    "Groups": [
                                        {
                                            "Dimension": "redirect_protocol",
                                            "GroupParameters": [
                                                {
                                                    "Parameters": [
                                                        {
                                                            "Name": "status_code",
                                                            "Values": [
                                                                "301"
                                                            ]
                                                        },
                                                        {
                                                            "Name": "protocol",
                                                            "Values": [
                                                                "https"
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    }
                ]
            }
        ]
    }
}

错误码

如果响应正文的 ResponseMetadata 字段中包含 Error 字段,则表示 API 请求失败。更多关于错误码的信息,参见错误码。

最近更新时间:2026.09.18 17:49:51
这个页面对您有帮助吗?
有用
有用
无用
无用