文档首页> 内容分发网络 CDN> API参考> API> 域名配置> 修改域名全量配置接口
更新时间:2024-05-30 GMT+08:00
分享

修改域名全量配置接口

功能介绍

修改域名配置接口, 支持修改业务类型、服务范围、备注、IPv6开关、回源方式、回源URL改写、高级回源、Range回源、回源跟随、回源是否校验Etag、回源超时时间、回源请求头、HTTPS配置、TLS版本配置、强制跳转、HSTS、HTTP/2、 OCSP Stapling、QUIC、缓存规则、状态码缓存时间、防盗链、IP黑白名单、 Use-Agent黑白名单、URL鉴权配置、远程鉴权配置、IP访问限频、 HTTP header配置、自定义错误页面配置、智能压缩、请求限速配置、WebSocket配置、视频拖拽、回源SNI、访问URL重写、浏览器缓存过期时间、区域访问控制。

调用方法

请参见如何调用API

URI

PUT /v1.1/cdn/configuration/domains/{domain_name}/configs

表1 路径参数

参数

是否必选

参数类型

描述

domain_name

String

加速域名。

表2 Query参数

参数

是否必选

参数类型

描述

enterprise_project_id

String

当用户开启企业项目功能时,该参数生效,表示修改当前企业项目下加速域名的配置,"all"代表所有项目。

说明:

当使用子账号调用接口时,该参数必传。 您可以通过调用企业项目管理服务(EPS)的查询企业项目列表接口(ListEnterpriseProject)查询企业项目id。

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token, 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

表4 请求Body参数

参数

是否必选

参数类型

描述

configs

Configs object

配置项。

表5 Configs

参数

是否必选

参数类型

描述

business_type

String

业务类型:

  • web:网站加速;

  • download:文件下载加速;

  • video:点播加速。

说明:

暂不支持“全站加速”变更为其它业务类型。

service_area

String

服务区域:

  • mainland_china:中国大陆;

  • global:全球;

  • outside_mainland_china:中国大陆境外。

说明:

暂不支持“中国大陆”与“中国大陆境外”互相直接切换。

remark

String

给域名添加备注,字符长度范围0-200。

origin_request_header

Array of OriginRequestHeader objects

回源请求头改写, 该功能将覆盖原有配置(清空之前的配置),在使用此接口时,请上传全量头部信息。

http_response_header

Array of HttpResponseHeader objects

http header配置, 该功能将覆盖原有配置(清空之前的配置),在使用此接口时,请上传全量头部信息。

url_auth

UrlAuth object

URL鉴权。

https

HttpPutBody object

证书设置

sources

Array of SourcesConfig objects

源站配置。

origin_protocol

String

回源协议,follow:协议跟随回源,http:HTTP回源(默认),https:https回源。

origin_follow302_status

String

回源跟随,on:开启,off:关闭。

cache_rules

Array of CacheRules objects

缓存规则。

ip_filter

IpFilter object

IP黑白名单。

referer

RefererConfig object

防盗链。

force_redirect

ForceRedirectConfig object

强制跳转。

compress

Compress object

智能压缩。

cache_url_parameter_filter

CacheUrlParameterFilter object

缓存url参数配置,

说明:

此参数作为旧参数,将于近期下线,建议使用CacheRules设置URL参数。

ipv6_accelerate

Integer

ipv6设置,1:打开;0:关闭。

error_code_cache

Array of ErrorCodeCache objects

状态码缓存时间。

origin_range_status

String

Range回源,即分片回源,开启: on,关闭: off。

说明:

开启Range回源的前提是您的源站支持Range请求,即HTTP请求头中包含Range字段,否则可能导致回源失败。

user_agent_filter

UserAgentFilter object

UA黑白名单设置

origin_request_url_rewrite

Array of OriginRequestUrlRewrite objects

改写回源URL,最多配置20条。

flexible_origin

Array of flexibleOrigins objects

高级回源,最多配置20条。

slice_etag_status

String

回源是否校验ETag,on:开启,off:关闭。

origin_receive_timeout

Integer

回源超时时间,范围:5-60,单位:秒。

remote_auth

commonRemoteAuth object

远程鉴权配置。

websocket

webSocketSeek object

webSocket配置。

说明:

只有全站加速的域名支持该配置。

video_seek

videoSeek object

视频拖拽配置。

说明:
  1. 需同步开启FLV、MP4格式文件的URL参数功能,并选择“忽略参数”。

  2. 关闭视频拖拽功能时,FLV时间拖拽功能失效。

request_limit_rules

Array of RequestLimitRules objects

请求限速。

ip_frequency_limit

IpFrequencyLimit object

IP访问限频,通过对单IP每秒访问单个节点的次数限制,实现CC攻击防御及恶意盗刷防护。

hsts

Hsts object

HSTS:配置HSTS后,将强制客户端(如浏览器)使用 HTTPS 协议访问服务器,提升访问安全性。

quic

Quic object

QUIC协议。

error_code_redirect_rules

Array of ErrorCodeRedirectRules objects

自定义错误页面。

sni

Sni object

回源SNI。

request_url_rewrite

Array of RequestUrlRewrite objects

访问URL重写。

browser_cache_rules

Array of BrowserCacheRules objects

浏览器缓存过期时间。

access_area_filter

Array of AccessAreaFilter objects

区域访问控制。

说明:
  • 使用该功能需要提交工单开通区域访问控制功能。

  • CDN会定期更新IP地址库,部分未在地址库的IP将无法识别到所属位置。如果CDN无法识别用户所在位置,将采取放行策略,返回对应的资源给用户。

表6 OriginRequestHeader

参数

是否必选

参数类型

描述

name

String

设置回源请求头参数。格式要求:长度1-64,由数字,大小写字母,中划线组成,只能以字母开头。

value

String

设置回源请求头参数的值。当为删除动作时,可不填。自定义回源请求头参数长度范围1-1000,不支持中文,不支持变量配置,如:$client_ip,$remote_port等。

action

String

回源请求头设置类型。delete:删除,set:设置。同一个请求头字段只允许删除或者设置。设置:若原始回源请求中不存在该字段,先执行新增再执行设置。

表7 HttpResponseHeader

参数

是否必选

参数类型

描述

name

String

设置HTTP响应头参数。取值:"Content-Disposition", "Content-Language", "Access-Control-Allow-Origin","Access-Control-Allow-Methods", "Access-Control-Max-Age", "Access-Control-Expose-Headers"或自定义头部。格式要求:长度1-100,由数字,大小写字母,中划线组成,只能以字母开头。

value

String

设置HTTP响应头参数的值。当为删除动作时,可不填。自定义HTTP响应头参数长度范围1-1000,支持字母、数字和特定字符,如:.-_*#!&+|^~'"/:;,=@?<> 等。

action

String

设置http响应头操作类型,取值“set/delete”。set代表设置,delete代表删除。

表8 UrlAuth

参数

是否必选

参数类型

描述

status

String

是否开启URL鉴权,on:开启,off:关闭。

type

String

鉴权方式 type_a:鉴权方式A type_b:鉴权方式B type_c1:鉴权方式C1 type_c2:鉴权方式C2

expire_time

Integer

过期时间:范围:0-31536000单位为秒。

sign_method

String

加密的算法 可选择md5或sha256

match_type

String

鉴权范围,目前仅支持配置所有文件参与鉴权,all:所有文件。

inherit_config

InheritConfig object

鉴权继承,为M3U8/MPD索引文件下的TS/MP4文件添加鉴权参数,解决因鉴权不通过导致的TS/MP4文件无法播放的问题。

key

String

鉴权KEY 由6-32位大小写字母、数字构成。

backup_key

String

鉴权KEY(备) 由6-32位大小写字母、数字构成。

sign_arg

String

鉴权参数:1-100位可以由大小写字母、数字、下划线构成(不能以数字开头)。

time_format

String

时间格式 dec:十进制 hex:十六进制 鉴权方式A:只支持十进制 鉴权方式B:只支持十进制 鉴权方式C1:只支持十六进制鉴权方式 鉴权方式C2:支持十进制/十六进制

表9 InheritConfig

参数

是否必选

参数类型

描述

status

String

是否开启鉴权继承,on:开启,off:关闭。

inherit_type

String

鉴权继承配置, m3u8:M3U8,mpd:MPD,输入多个时用“,”分开,例如“m3u8,mpd”

说明:

开启鉴权继承时,该参数必填。

inherit_time_type

String

鉴权继承的文件类型时间, sys_time:当前系统时间,parent_url_time:与m3u8和mpd访问链接保持一致。

说明:

开启鉴权继承时,该参数必填。

表10 HttpPutBody

参数

是否必选

参数类型

描述

https_status

String

HTTPS证书是否启用,on:开启,off:关闭。

certificate_type

String

证书类型,server:国际证书;server_sm:国密证书。

certificate_source

Integer

证书来源,0:自有证书。

说明:

证书开启时必传

certificate_name

String

证书名字,长度限制为3-64字符。

说明:

当证书开启时必传。

certificate_value

String

HTTPS协议使用的证书内容,当证书开启时必传。

说明:

PEM编码格式。

private_key

String

HTTPS协议使用的私钥,当证书开启时必传。

说明:

PEM编码格式。

enc_certificate_value

String

加密证书内容,证书类型为国密证书时必传。

说明:

PEM编码格式。

enc_private_key

String

加密私钥内容,证书类型为国密证书时必传。

说明:

PEM编码格式。

certificates

Array of CertificatesPutBody objects

配置双证书时必传,需要同时传入国际证书和国密证书,不支持传两个国际证书或两个国密证书。

说明:
  • 您也可以在certificates参数下传入一个国际证书或一个国密证书。

  • 如果certificates传了证书(国际证书、国密证书或国际+国密双证书),外层证书配置将失效,仅保留当前参数传入的证书信息。

http2_status

String

是否使用HTTP2.0,on:是,off:否。

说明:

默认关闭,https_status=off时,该值不生效。

tls_version

String

传输层安全性协议, 目前支持TLSv1.0/1.1/1.2/1.3四个版本的协议,CDN默认开启TLS1.1/1.2/1.3,不可全部关闭。

说明:

1.需开启连续或单个版本号,例:不可仅开启TLS1.0/1.2而关闭TLS1.1。 2.多版本开启时,使用逗号拼接传输,例:TLSv1.1,TLSv1.2。

ocsp_stapling_status

String

是否开启ocsp stapling,on:是,off:否。

表11 CertificatesPutBody

参数

是否必选

参数类型

描述

certificate_type

String

证书类型,server:国际证书;server_sm:国密证书。

certificate_name

String

证书名字,长度限制为3-64字符。

certificate_value

String

HTTPS协议使用的证书内容。

说明:

PEM编码格式。

private_key

String

HTTPS协议使用的私钥。

说明:

PEM编码格式。

enc_certificate_value

String

加密证书内容,证书类型为国密证书时必传。

说明:

PEM编码格式。

enc_private_key

String

加密私钥内容,证书类型为国密证书时必传。

说明:

PEM编码格式。

表12 SourcesConfig

参数

是否必选

参数类型

描述

origin_type

String

源站类型,

  • ipaddr:源站IP;

  • domain:源站域名;

  • obs_bucket:OBS桶域名;

  • third_bucket:第三方桶。

origin_addr

String

源站IP或者域名。

priority

Integer

源站优先级,70:主,30:备。

weight

Integer

权重,取值范围1-100。

obs_web_hosting_status

String

是否开启OBS静态网站托管,源站类型为obs_bucket时传递,off:关闭,on:开启。

http_port

Integer

HTTP端口,默认80,端口取值取值范围1-65535。

https_port

Integer

HTTPS端口,默认443,端口取值取值范围1-65535。

host_name

String

回源HOST,默认加速域名。

obs_bucket_type

String

OBS桶类型,源站类型是“OBS桶域名”时需要传该参数,不传默认为“public”。

  • private: 私有桶(除桶ACL授权外的其他用户无桶的访问权限)。

  • public: 公有桶(任何用户都可以对桶内对象进行读操作)。

bucket_access_key

String

第三方对象存储访问密钥。

说明:

源站类型为第三方桶时必填

bucket_secret_key

String

第三方对象存储密钥。

说明:

源站类型为第三方桶时必填

bucket_region

String

第三方对象存储区域。

说明:

源站类型为第三方桶时必填

bucket_name

String

第三方对象存储名称。

说明:

源站类型为第三方桶时必填

表13 CacheRules

参数

是否必选

参数类型

描述

match_type

String

匹配类型:

  • all:匹配所有文件,

  • file_extension:按文件后缀匹配,

  • catalog:按目录匹配,

  • full_path:全路径匹配,

  • home_page:按首页匹配。

    说明:

    配置单条缓存规则时,可不传,默认为all。 配置多条缓存规则时,此参数必传。

match_value

String

缓存匹配设置, 当match_type为all时,为空。当match_type为file_extension时,为文件后缀,输入首字符为“.”,以“,”进行分隔, 如.jpg,.zip,.exe,并且输入的文 件名后缀总数不超过20个。 当match_type为catalog时,为目录路径,输入要求以“/”作为首字符, 以“,”进行分隔,如/test/folder01,/test/folder02,并且输入的目录路径总数不超过20个。 当match_type为full_path时,为全路径,输入要求以“/”作为首字符,支持匹配指定目录下的具体文件,或者带通配符“*”的文件,单条全路径缓存规则里仅支持配置一个全路径,如/test/index.html或/test/*.jpg。 当match_type为home_page时,为空。

ttl

Integer

缓存过期时间,最大支持365天。

说明:

默认值为0。

ttl_unit

String

缓存过期时间单位,s:秒;m:分;h:小时;d:天。

priority

Integer

此条缓存规则的优先级, 默认值1,数值越大,优先级越高,取值范围为1-100,优先级不能相同。

follow_origin

String

缓存遵循源站开关,on:打开,off:关闭。 > 默认值为off。

url_parameter_type

String

URL参数:

  • del_params:忽略指定URL参数,

  • reserve_params:保留指定URL参数,

  • ignore_url_params:忽略全部URL参数,

  • full_url:使用完整URL参数。

    说明:

    不传此参数时,默认为full_url。

url_parameter_value

String

URL参数值,最多设置10条,以","分隔。 > 当url_parameter_type为del_params或reserve_params时必填。

表14 IpFilter

参数

是否必选

参数类型

描述

type

String

IP黑白名单类型,off:关闭IP黑白名单,black:IP黑名单,white:IP白名单。

value

String

配置IP黑白名单,当type=off时,非必传, 支持IPv6,支持配置IP地址和IP&掩码格式的网段, 多条规则用“,”分割,最多支持配置500个, 多个完全重复的IP/IP段将合并为一个,不支持带通配符的地址,如192.168.0.*。

表15 RefererConfig

参数

是否必选

参数类型

描述

type

String

Referer黑白名单类型,off:关闭Referer黑白名单,black:Referer黑名单,white:Referer白名单。

value

String

域名或IP地址,以“,”进行分割,域名、IP地址可以混合输入,支持泛域名和带端口的域名。域名、IP地址总数不超过400个,端口取值范围1-65535。

include_empty

Boolean

是否包含空Referer,如果是黑名单并开启该选项,则表示无referer不允许访问,如果是白名单并开启该选项,则表示无referer允许访问,true:包含空,false:不包含空,默认值false。

表16 ForceRedirectConfig

参数

是否必选

参数类型

描述

status

String

强制跳转开关(on:打开, off:关闭)。

type

String

强制跳转类型(http:强制跳转HTTP,https:强制跳转HTTPS)。

redirect_code

Integer

重定向跳转码301,302。

表17 Compress

参数

是否必选

参数类型

描述

status

String

智能压缩开关(on:开启 off:关闭)。

type

String

智能压缩类型(gzip:gzip压缩,br:brotli压缩)。

file_type

String

压缩格式,内容总长度不可超过200个字符, 多种格式用“,”分割,每组内容不可超过50个字符, 开启状态下,首次传空时默认值为.js,.html,.css,.xml,.json,.shtml,.htm,否则为上次设置的结果。

表18 CacheUrlParameterFilter

参数

是否必选

参数类型

描述

type

String

缓存URL参数操作类型:

  • full_url:缓存所有参数;

  • ignore_url_params:忽略所有参数;

  • del_params:忽略指定URL参数;

  • reserve_params:保留指定URL参数。

    说明:

    本接口参数有调整,参数替换如下:

    • del_params替代del_args。

    • reserve_params替代reserve_args。

value

String

参数值,多个参数使用分号分隔。

表19 ErrorCodeCache

参数

是否必选

参数类型

描述

code

Integer

允许配置的错误码: 400, 403, 404, 405, 414, 500, 501, 502, 503, 504

ttl

Integer

错误码缓存时间,单位为秒,范围0-31,536,000(一年默认为365天)。

表20 UserAgentFilter

参数

是否必选

参数类型

描述

type

String

UA黑白名单类型 off:关闭UA黑白名单; black:UA黑名单; white:UA白名单;

value

String

配置UA黑白名单,当type=off时,非必传。最多配置10条规则,单条规则不超过100个字符,多条规则用“,”分割。

ua_list

Array of strings

配置UA黑白名单,当type=off时,非必传。最多配置10条规则,单条规则不超过100个字符, 同时配置value和ua_list时,ua_list生效。

表21 OriginRequestUrlRewrite

参数

是否必选

参数类型

描述

priority

Integer

回源URL改写规则的优先级。 优先级设置具有唯一性,不支持多条回源URL改写规则设置同一优先级,且优先级不能输入为空。 多条规则下,不同规则中的相同资源内容,CDN按照优先级高的规则执行URL改写。 取值为1-100之间的整数,数值越大优先级越高。

match_type

String

匹配类型, all:所有文件, file_path:URI路径, wildcard:通配符。 full_path: 全路径

source_url

String

需要替换的URI。 改写后的URI以正斜线(/)开头的URI,不含http(s)://头及域名。 长度不超过512个字符。 支持通配符*匹配,如:/test/*/*.mp4。 匹配方式为“所有文件”时,不支持配置参数。

target_url

String

以正斜线(/)开头的URI,不含http(s)://头及域名。 长度不超过256个字符。 通配符 * 可通过$n捕获(n=1,2,3...,例如:/newtest/$1/$2.jpg)。

表22 flexibleOrigins

参数

是否必选

参数类型

描述

match_type

String

URI的匹配方式,支持文件后缀(file_extension)和路径前缀(file_path)。

match_pattern

String

file_extension(文件后缀): 支持所有格式的文件类型。 输入首字符为“.”,以“;”进行分隔。 输入的文件后缀名总数不能超过20个。 file_path(目录路径):输入要求以“/”作为首字符,以“;”进行分隔,输入的目录路径总数不能超过20个。

priority

Integer

优先级取值范围为1-100,数值越大优先级越高。

back_sources

Array of backSources objects

回源信息。

说明:

每个目录的回源源站数量不超过1个。

表23 backSources

参数

是否必选

参数类型

描述

sources_type

String

源站类型, ipaddr:源站IP,domain:源站域名,obs_bucket:OBS桶域名。

ip_or_domain

String

源站IP或者域名。

obs_bucket_type

String

OBS桶类型。

  • “private”: 私有桶;

  • “public”: 公有桶。

http_port

Integer

HTTP端口,取值范围:1-65535。

https_port

Integer

HTTPS端口,取值范围:1-65535。

表24 commonRemoteAuth

参数

是否必选

参数类型

描述

remote_authentication

String

是否开启远程鉴权(on:开启,off:关闭)。

remote_auth_rules

RemoteAuthRule object

远程鉴权配置。

表25 RemoteAuthRule

参数

是否必选

参数类型

描述

auth_server

String

可访问的鉴权服务器地址。 输入的URL必须有“http”或“https”。不能是localhost或127.0.0.1这类本地地址。 不能是CDN的加速域名。

request_method

String

鉴权服务器支持的请求方法,支持GET、POST、HEAD。

file_type_setting

String

all(所有文件类型):所有文件均参与鉴权。 specific_file(指定文件类型):指定类型的文件参与鉴权。示例:jpg|MP4。 文件类型不区分大小写,即:jpg和JPG代表同一种文件类型,多个文件类型用“|”分割。

specified_file_type

String

字符总数不能超过512,当file_type_setting等于specific_file时为必选,其余情况为空, 由大小写字母和数字构成,文件类型用竖线分隔,例如jpg|mp4,只有在必选情况下才会对该字段做校验。

reserve_args_setting

String

设置用户请求中需要参与鉴权的参数,可选reserve_all_args(保留所有URL参数)、reserve_specific_args(保留指定URL参数)、ignore_all_args(忽略所有URL参数)。

reserve_args

String

当reserve_args_setting等于reserve_specific_args时为必选,其余情况为空,要保留的参数,多个参数用竖线分隔:key1|key2。

add_custom_args_rules

Array of customArgs objects

URL鉴权参数。

reserve_headers_setting

String

设置用户请求中参与鉴权请求头,可选reserve_all_headers(保留所有请求头参数)、reserve_specific_headers(保留指定请求头参数)、ignore_all_headers(忽略所有请求头参数)。

add_custom_headers_rules

Array of customArgs objects

请求头鉴权参数。

auth_success_status

String

设置鉴权成功时远程鉴权服务器返回给CDN节点的状态码。取值范围:2xx/3xx。

auth_failed_status

String

设置鉴权失败时远程鉴权服务器返回给CDN节点的状态码。取值范围:4xx/5xx。

response_status

String

设置鉴权失败时CDN节点返回给用户的状态码。取值范围:2xx/3xx/4xx/5xx。

timeout

Integer

设置鉴权超时时间,即从CDN转发鉴权请求开始,到CDN节点收到远程鉴权服务器返回的结果的时间。单位为毫秒,值为0或50-3000。

timeout_action

String

设置鉴权超时后,CDN节点如何处理用户请求。 pass(鉴权失败放过):鉴权超时后允许用户请求,返回对应的资源。 forbid(鉴权失败拒绝):鉴权超时后拒绝用户请求,返回配置的响应自定义状态码给用户。

reserve_headers

String

当reserve_headers_setting等于reserve_specific_headers时为必选,其余情况为空,要保留的请求头,多个请求头用竖线分隔:key1|key2。

表26 customArgs

参数

是否必选

参数类型

描述

type

String

参数类型,custom_var:自定义,nginx_preset_var:预置的变量。

key

String

参数,长度支持1-256,由数字0-9、字符a-z、A-Z,及特殊字符._-*#%|+^@?=组成。

value

String

当type为custom_var时长度支持1-256,由数字0-9、字符a-z、A-Z,及特殊字符._-*#%|+^@?=组成, 当type为nginx_preset_var时,value只能输入$http_host、$http_user_agent、$http_referer、$http_x_forwarded_for、 $http_content_type、$remote_addr、$scheme、$server_protocol、$request_uri、$uri、$args、$request_method。

表27 webSocketSeek

参数

是否必选

参数类型

描述

status

String

开关, on 开启,off 关闭。

timeout

Integer

请求建立连接后,会话的保持时间:范围:1-300,单位:秒。

表28 videoSeek

参数

是否必选

参数类型

描述

enable_video_seek

Boolean

视频拖拽开关, true:开启,false:关闭

说明:

当本字段设置为“false”时,查询域名配置接口将不会返回视频拖拽配置信息。

enable_flv_by_time_seek

Boolean

flv时间拖拽开关, true:开启,false:关闭。

start_parameter

String

自定义用户请求URL中视频播放的开始参数,支持使用数字0-9、字符a-z、A-Z,及"_",长度≤64个字符。

end_parameter

String

自定义用户请求URL中视频播放的结束参数,支持使用数字0-9、字符a-z、A-Z,及"_",长度≤64个字符。

表29 RequestLimitRules

参数

是否必选

参数类型

描述

status

String

status只支持on,off无效。

说明:

request_limit_rules字段置空时代表关闭请求限速功能。 旧接口中的参数,后续将下线。

priority

Integer

优先级,值越大,优先级越高,取值范围:1-100。

match_type

String

匹配类型,all:所有文件,catalog:目录。

match_value

String

匹配类型值。 当match_type为all时传空值,例如:""; 当match_type为catalog时传目录地址,以“/”作为首字符,例如:"/test"。

说明:

值为catalog的时候必填

type

String

限速方式,当前仅支持按流量大小限速,取值为size。

limit_rate_after

Long

限速条件,type=size,limit_rate_after=50表示从传输表示传输50个字节后开始限速且限速值为limit_rate_value, 单位byte,取值范围:0-1073741824。

limit_rate_value

Integer

限速值,单位Bps,取值范围 0-104857600。

表30 IpFrequencyLimit

参数

是否必选

参数类型

描述

status

String

状态,on:打开,off:关闭。

qps

Integer

访问阈值,单位:次/秒,取值范围:1-100000。

说明:

当开启ip限频时,访问阈值必填。

表31 Hsts

参数

是否必选

参数类型

描述

status

String

状态,on:打开,off:关闭。

max_age

Integer

过期时间,即:响应头“Strict-Transport-Security”在客户端的缓存时间。单位:秒,取值范围:0-63072000。

说明:

status参数为on时,必传。

include_subdomains

String

包含子域名,on:包含,off:不包含。

说明:

status参数为on时,必传。

表32 Quic

参数

是否必选

参数类型

描述

status

String

状态,on:打开,off:关闭。

表33 ErrorCodeRedirectRules

参数

是否必选

参数类型

描述

error_code

Integer

重定向的错误码,当前支持以下状态码 4xx:400, 403, 404, 405, 414, 416, 451 5xx:500, 501, 502, 503, 504。

target_code

Integer

重定向状态码,取值为301或302。

target_link

String

重定向的目标链接

表34 Sni

参数

是否必选

参数类型

描述

status

String

是否开启回源SNI,on:打开,off:关闭。

server_name

String

CDN节点回源需要访问的源站域名。如test.example.com。

说明:
  1. 开启回源SNI时必填。

  2. 不支持泛域名,仅支持输入数字、“-”、“.”、英文大小写字符。

表35 RequestUrlRewrite

参数

是否必选

参数类型

描述

condition

UrlRewriteCondition object

匹配条件。

redirect_status_code

Integer

重定向状态码。支持301、302、303、307。

redirect_url

String

重定向URL。重定向后的URL,以正斜线(/)开头,不含http://头及域名,如:/test/index.html。

  • 当匹配类型为全路径时,"*"可以用“$1”捕获,例如:匹配内容为/test/*.jpg,重定向URL配置为/newtest/$1.jpg,则用户请求/test/11.jpg时,$1捕获11,重定向后请求的URL为/newtest/11.jpg。

redirect_host

String

支持将客户端请求重定向到其他域名。

说明:

不填时默认为当前域名。 支持字符长度为1-255,必须以http://或https://开头,例如http://www.example.com。

execution_mode

String

执行规则:

  • redirect:如果请求的URL匹配了当前规则,该请求将被重定向到目标Path。执行完当前规则后,当存在其他配置规则时,会继续匹配剩余规则。

  • break:如果请求的URL匹配了当前规则,请求将被改写为目标Path。执行完当前规则后,当存在其他配置规则时,将不再匹配剩余规则,此时不支持配置重定向Host和重定向状态码,返回状态码200。

表36 UrlRewriteCondition

参数

是否必选

参数类型

描述

match_type

String

匹配类型。

  • catalog:指定目录下的文件需执行访问URL重写规则,

  • full_path:某个完整路径下的文件需执行访问URL重写规则。

match_value

String

匹配内容。当match_type为catalog时,为目录路径,输入要求以“/”作为首字符,以“,”进行分隔,如/test/folder01,/test/folder02,并且输入的目录路径总数不超过20个。当match_type为full_path时,为全路径,输入要求以“/”作为首字符,支持匹配指定目录下的具体文件,或者带通配符“*”的文件,单条全路径缓存规则里仅支持配置一个全路径,如/test/index.html或/test/*.jpg。

priority

Integer

访问URL重写规则的优先级。取值为1-100之间的整数,数值越大优先级越高。优先级设置具有唯一性,不支持多条规则设置同一优先级,且优先级不能为空。

表37 BrowserCacheRules

参数

是否必选

参数类型

描述

condition

BrowserCacheRulesCondition object

匹配条件。

cache_type

String

缓存生效类型:

  • follow_origin:遵循源站的缓存策略,即Cache-Control头部的设置,

  • ttl:浏览器缓存遵循当前规则设置的过期时间,

  • never:浏览器不缓存资源。

ttl

Integer

缓存过期时间,最大支持365天。

说明:

当缓存生效类型为ttl时必填。

ttl_unit

String

缓存过期时间单位,s:秒;m:分种;h:小时;d:天。

说明:

当缓存生效类型为ttl时必填。

表38 BrowserCacheRulesCondition

参数

是否必选

参数类型

描述

match_type

String

匹配类型:

  • all:匹配所有文件,

  • file_extension:按文件后缀匹配,

  • catalog:按目录匹配,

  • full_path:全路径匹配,

  • home_page:按首页匹配。

match_value

String

缓存匹配设置,当match_type为all时,为空。当match_type为file_extension时,为文件后缀,输入首字符为“.”,以“,”进行分隔, 如.jpg,.zip,.exe,并且输入的文 件名后缀总数不超过20个。 当match_type为catalog时,为目录,输入要求以“/”作为首字符, 以“,”进行分隔,如/test/folder01,/test/folder02,并且输入的目录路径总数不超过20个。 当match_type为full_path时,为全路径,输入要求以“/”作为首字符,支持匹配指定目录下的具体文件,或者带通配符“*”的文件,单条全路径缓存规则里仅支持配置一个全路径,如/test/index.html或/test/*.jpg。 当match_type为home_page时,为空。

priority

Integer

浏览器缓存的优先级,取值为1-100之间的整数,数值越大优先级越高。优先级设置具有唯一性,不支持多条规则设置同一优先级,且优先级不能为空。

表39 AccessAreaFilter

参数

是否必选

参数类型

描述

type

String

规则类型,黑、白名单二选一。

  • black: 黑名单,如果匹配到黑名单规则,则黑名单所选区域内的用户将无法访问当前资源,返回403状态码。

  • white: 白名单,白名单所选区域以外的用户均无法访问当前资源,返回403状态码。

content_type

String

生效类型。

  • all: 所有文件,所有文件均遵循配置的规则。

  • file_directory: 目录路径,指定目录路径的资源遵循配置的规则。

  • file_path: 全路径,指定路径的资源遵循配置的规则。

content_value

String

生效规则。当content_type为all时,为空或不传。 当content_type为file_directory时,输入要求以“/”作为首字符,多个目录以“,”进行分隔,如/test/folder01,/test/folder02,并且输入的目录路径总数不超过100个。 当content_type为file_path时,输入要求以“/”或“*”作为首字符,支持配置通配符“*”,通配符不能连续出现且不能超过两个。多个路径以“,”进行分割,如/test/a.txt,/test/b.txt,并且输出的总数不能超过100个。

说明:
  • 不允许配置两条完全一样的白名单或黑名单规则。

  • 仅允许配置一条生效类型为“所有文件”的规则。

area

String

配置规则适用的区域,多个区域以“,”进行分隔,支持的区域如:CN_IN:中国大陆,AF:阿富汗,IE:爱尔兰,EG:埃及,AU:澳大利亚等。具体的位置编码参见《附录-地理位置编码》查询。

exception_ip

String

例外IP,配置指定IP不执行当前规则。

响应参数

请求示例

PUT https://cdn.myhuaweicloud.com/v1.1/cdn/configuration/domains/www.example.com/configs

{
  "configs" : {
    "origin_request_header" : [ {
      "name" : "test-name",
      "value" : "test_value",
      "action" : "set"
    } ],
    "http_response_header" : [ {
      "name" : "test-name",
      "value" : "test_value",
      "action" : "set"
    } ],
    "url_auth" : {
      "status" : "off"
    },
    "compress" : {
      "status" : "off"
    },
    "force_redirect" : {
      "status" : "on",
      "type" : "http",
      "redirect_code" : 301
    },
    "origin_protocol" : "follow",
    "referer" : {
      "type" : "black",
      "value" : "192.168.0.0",
      "include_empty" : true
    },
    "ip_filter" : {
      "type" : "black",
      "value" : "192.168.0.0"
    },
    "origin_follow302_status" : "off",
    "cache_rules" : [ {
      "match_type" : "file_extension",
      "match_value" : ".zip",
      "ttl" : 0,
      "ttl_unit" : "h",
      "priority" : 10,
      "follow_origin" : "off",
      "url_parameter_type" : "del_params",
      "url_parameter_value" : "test_param"
    } ],
    "sources" : [ {
      "origin_addr" : "www.example.com",
      "origin_type" : "domain",
      "priority" : 70,
      "http_port" : 80,
      "https_port" : 443
    } ],
    "flexible_origin" : [ {
      "priority" : 1,
      "match_type" : "file_path",
      "match_pattern" : "/test",
      "back_sources" : [ {
        "sources_type" : "domain",
        "ip_or_domain" : "www.back.example.com"
      } ]
    } ],
    "slice_etag_status" : "off",
    "ipv6_accelerate" : 1,
    "origin_receive_timeout" : 30,
    "remote_auth" : {
      "remote_authentication" : "on",
      "remote_auth_rules" : {
        "auth_server" : "https://192.168.0.0",
        "request_method" : "GET",
        "file_type_setting" : "all",
        "reserve_args_setting" : "reserve_all_args",
        "reserve_headers_setting" : "reserve_specific_headers",
        "auth_success_status" : "200",
        "auth_failed_status" : "403",
        "response_status" : "403",
        "timeout" : 500,
        "timeout_action" : "pass",
        "reserve_headers" : "sf",
        "add_custom_args_rules" : [ {
          "type" : "nginx_preset_var",
          "key" : "http_host",
          "value" : "$http_host"
        } ],
        "add_custom_headers_rules" : [ {
          "type" : "nginx_preset_var",
          "key" : "http_host",
          "value" : "$http_host"
        } ]
      }
    },
    "websocket" : {
      "status" : "on",
      "timeout" : 60
    },
    "video_seek" : {
      "enable_video_seek" : true,
      "enable_flv_by_time_seek" : true,
      "start_parameter" : "start",
      "end_parameter" : "end"
    },
    "request_limit_rules" : [ {
      "status" : "on",
      "match_type" : "catalog",
      "match_value" : "/test",
      "type" : "size",
      "limit_rate_after" : 1024,
      "limit_rate_value" : 50,
      "priority" : 88
    } ],
    "sni" : {
      "status" : "on",
      "server_name" : "test.example.com"
    },
    "request_url_rewrite" : [ {
      "condition" : {
        "match_type" : "full_path",
        "match_value" : "/test/*.jpg",
        "priority" : 10
      },
      "redirect_status_code" : 301,
      "redirect_url" : "/test/index.html",
      "redirect_host" : "http://www.example.com",
      "execution_mode" : "redirect"
    } ],
    "browser_cache_rules" : [ {
      "condition" : {
        "match_type" : "full_path",
        "match_value" : "/test/*.jpg",
        "priority" : 10
      },
      "cache_type" : "ttl",
      "ttl" : 20,
      "ttl_unit" : "h"
    } ],
    "access_area_filter" : [ {
      "type" : "black",
      "content_type" : "all",
      "area" : "CN_IN,AU",
      "exception_ip" : "0.0.0.0"
    } ]
  }
}

响应示例

SDK代码示例

SDK代码示例如下。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.cdn.v2.region.CdnRegion;
import com.huaweicloud.sdk.cdn.v2.*;
import com.huaweicloud.sdk.cdn.v2.model.*;

import java.util.List;
import java.util.ArrayList;

public class UpdateDomainFullConfigSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new GlobalCredentials()
                .withAk(ak)
                .withSk(sk);

        CdnClient client = CdnClient.newBuilder()
                .withCredential(auth)
                .withRegion(CdnRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateDomainFullConfigRequest request = new UpdateDomainFullConfigRequest();
        request.withEnterpriseProjectId("<enterprise_project_id>");
        ModifyDomainConfigRequestBody body = new ModifyDomainConfigRequestBody();
        List<AccessAreaFilter> listConfigsAccessAreaFilter = new ArrayList<>();
        listConfigsAccessAreaFilter.add(
            new AccessAreaFilter()
                .withType("black")
                .withContentType("all")
                .withArea("CN_IN,AU")
                .withExceptionIp("0.0.0.0")
        );
        BrowserCacheRulesCondition conditionBrowserCacheRules = new BrowserCacheRulesCondition();
        conditionBrowserCacheRules.withMatchType("full_path")
            .withMatchValue("/test/*.jpg")
            .withPriority(10);
        List<BrowserCacheRules> listConfigsBrowserCacheRules = new ArrayList<>();
        listConfigsBrowserCacheRules.add(
            new BrowserCacheRules()
                .withCondition(conditionBrowserCacheRules)
                .withCacheType("ttl")
                .withTtl(20)
                .withTtlUnit("h")
        );
        UrlRewriteCondition conditionRequestUrlRewrite = new UrlRewriteCondition();
        conditionRequestUrlRewrite.withMatchType("full_path")
            .withMatchValue("/test/*.jpg")
            .withPriority(10);
        List<RequestUrlRewrite> listConfigsRequestUrlRewrite = new ArrayList<>();
        listConfigsRequestUrlRewrite.add(
            new RequestUrlRewrite()
                .withCondition(conditionRequestUrlRewrite)
                .withRedirectStatusCode(301)
                .withRedirectUrl("/test/index.html")
                .withRedirectHost("http://www.example.com")
                .withExecutionMode("redirect")
        );
        Sni sniConfigs = new Sni();
        sniConfigs.withStatus("on")
            .withServerName("test.example.com");
        List<RequestLimitRules> listConfigsRequestLimitRules = new ArrayList<>();
        listConfigsRequestLimitRules.add(
            new RequestLimitRules()
                .withStatus("on")
                .withPriority(88)
                .withMatchType("catalog")
                .withMatchValue("/test")
                .withType("size")
                .withLimitRateAfter(1024L)
                .withLimitRateValue(50)
        );
        VideoSeek videoSeekConfigs = new VideoSeek();
        videoSeekConfigs.withEnableVideoSeek(true)
            .withEnableFlvByTimeSeek(true)
            .withStartParameter("start")
            .withEndParameter("end");
        WebSocketSeek websocketConfigs = new WebSocketSeek();
        websocketConfigs.withStatus("on")
            .withTimeout(60);
        List<CustomArgs> listRemoteAuthRulesAddCustomHeadersRules = new ArrayList<>();
        listRemoteAuthRulesAddCustomHeadersRules.add(
            new CustomArgs()
                .withType("nginx_preset_var")
                .withKey("http_host")
                .withValue("$http_host")
        );
        List<CustomArgs> listRemoteAuthRulesAddCustomArgsRules = new ArrayList<>();
        listRemoteAuthRulesAddCustomArgsRules.add(
            new CustomArgs()
                .withType("nginx_preset_var")
                .withKey("http_host")
                .withValue("$http_host")
        );
        RemoteAuthRule remoteAuthRulesRemoteAuth = new RemoteAuthRule();
        remoteAuthRulesRemoteAuth.withAuthServer("https://192.168.0.0")
            .withRequestMethod("GET")
            .withFileTypeSetting("all")
            .withReserveArgsSetting("reserve_all_args")
            .withAddCustomArgsRules(listRemoteAuthRulesAddCustomArgsRules)
            .withReserveHeadersSetting("reserve_specific_headers")
            .withAddCustomHeadersRules(listRemoteAuthRulesAddCustomHeadersRules)
            .withAuthSuccessStatus("200")
            .withAuthFailedStatus("403")
            .withResponseStatus("403")
            .withTimeout(500)
            .withTimeoutAction("pass")
            .withReserveHeaders("sf");
        CommonRemoteAuth remoteAuthConfigs = new CommonRemoteAuth();
        remoteAuthConfigs.withRemoteAuthentication("on")
            .withRemoteAuthRules(remoteAuthRulesRemoteAuth);
        List<BackSources> listFlexibleOriginBackSources = new ArrayList<>();
        listFlexibleOriginBackSources.add(
            new BackSources()
                .withSourcesType("domain")
                .withIpOrDomain("www.back.example.com")
        );
        List<FlexibleOrigins> listConfigsFlexibleOrigin = new ArrayList<>();
        listConfigsFlexibleOrigin.add(
            new FlexibleOrigins()
                .withMatchType("file_path")
                .withMatchPattern("/test")
                .withPriority(1)
                .withBackSources(listFlexibleOriginBackSources)
        );
        Compress compressConfigs = new Compress();
        compressConfigs.withStatus("off");
        ForceRedirectConfig forceRedirectConfigs = new ForceRedirectConfig();
        forceRedirectConfigs.withStatus("on")
            .withType("http")
            .withRedirectCode(301);
        RefererConfig refererConfigs = new RefererConfig();
        refererConfigs.withType("black")
            .withValue("192.168.0.0")
            .withIncludeEmpty(true);
        IpFilter ipFilterConfigs = new IpFilter();
        ipFilterConfigs.withType("black")
            .withValue("192.168.0.0");
        List<CacheRules> listConfigsCacheRules = new ArrayList<>();
        listConfigsCacheRules.add(
            new CacheRules()
                .withMatchType("file_extension")
                .withMatchValue(".zip")
                .withTtl(0)
                .withTtlUnit("h")
                .withPriority(10)
                .withFollowOrigin("off")
                .withUrlParameterType("del_params")
                .withUrlParameterValue("test_param")
        );
        List<SourcesConfig> listConfigsSources = new ArrayList<>();
        listConfigsSources.add(
            new SourcesConfig()
                .withOriginType("domain")
                .withOriginAddr("www.example.com")
                .withPriority(70)
                .withHttpPort(80)
                .withHttpsPort(443)
        );
        UrlAuth urlAuthConfigs = new UrlAuth();
        urlAuthConfigs.withStatus("off");
        List<HttpResponseHeader> listConfigsHttpResponseHeader = new ArrayList<>();
        listConfigsHttpResponseHeader.add(
            new HttpResponseHeader()
                .withName("test-name")
                .withValue("test_value")
                .withAction("set")
        );
        List<OriginRequestHeader> listConfigsOriginRequestHeader = new ArrayList<>();
        listConfigsOriginRequestHeader.add(
            new OriginRequestHeader()
                .withName("test-name")
                .withValue("test_value")
                .withAction("set")
        );
        Configs configsbody = new Configs();
        configsbody.withOriginRequestHeader(listConfigsOriginRequestHeader)
            .withHttpResponseHeader(listConfigsHttpResponseHeader)
            .withUrlAuth(urlAuthConfigs)
            .withSources(listConfigsSources)
            .withOriginProtocol("follow")
            .withOriginFollow302Status("off")
            .withCacheRules(listConfigsCacheRules)
            .withIpFilter(ipFilterConfigs)
            .withReferer(refererConfigs)
            .withForceRedirect(forceRedirectConfigs)
            .withCompress(compressConfigs)
            .withIpv6Accelerate(1)
            .withFlexibleOrigin(listConfigsFlexibleOrigin)
            .withSliceEtagStatus("off")
            .withOriginReceiveTimeout(30)
            .withRemoteAuth(remoteAuthConfigs)
            .withWebsocket(websocketConfigs)
            .withVideoSeek(videoSeekConfigs)
            .withRequestLimitRules(listConfigsRequestLimitRules)
            .withSni(sniConfigs)
            .withRequestUrlRewrite(listConfigsRequestUrlRewrite)
            .withBrowserCacheRules(listConfigsBrowserCacheRules)
            .withAccessAreaFilter(listConfigsAccessAreaFilter);
        body.withConfigs(configsbody);
        request.withBody(body);
        try {
            UpdateDomainFullConfigResponse response = client.updateDomainFullConfig(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdkcdn.v2.region.cdn_region import CdnRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcdn.v2 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = GlobalCredentials(ak, sk) \

    client = CdnClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CdnRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateDomainFullConfigRequest()
        request.enterprise_project_id = "<enterprise_project_id>"
        listAccessAreaFilterConfigs = [
            AccessAreaFilter(
                type="black",
                content_type="all",
                area="CN_IN,AU",
                exception_ip="0.0.0.0"
            )
        ]
        conditionBrowserCacheRules = BrowserCacheRulesCondition(
            match_type="full_path",
            match_value="/test/*.jpg",
            priority=10
        )
        listBrowserCacheRulesConfigs = [
            BrowserCacheRules(
                condition=conditionBrowserCacheRules,
                cache_type="ttl",
                ttl=20,
                ttl_unit="h"
            )
        ]
        conditionRequestUrlRewrite = UrlRewriteCondition(
            match_type="full_path",
            match_value="/test/*.jpg",
            priority=10
        )
        listRequestUrlRewriteConfigs = [
            RequestUrlRewrite(
                condition=conditionRequestUrlRewrite,
                redirect_status_code=301,
                redirect_url="/test/index.html",
                redirect_host="http://www.example.com",
                execution_mode="redirect"
            )
        ]
        sniConfigs = Sni(
            status="on",
            server_name="test.example.com"
        )
        listRequestLimitRulesConfigs = [
            RequestLimitRules(
                status="on",
                priority=88,
                match_type="catalog",
                match_value="/test",
                type="size",
                limit_rate_after=1024,
                limit_rate_value=50
            )
        ]
        videoSeekConfigs = VideoSeek(
            enable_video_seek=True,
            enable_flv_by_time_seek=True,
            start_parameter="start",
            end_parameter="end"
        )
        websocketConfigs = WebSocketSeek(
            status="on",
            timeout=60
        )
        listAddCustomHeadersRulesRemoteAuthRules = [
            CustomArgs(
                type="nginx_preset_var",
                key="http_host",
                value="$http_host"
            )
        ]
        listAddCustomArgsRulesRemoteAuthRules = [
            CustomArgs(
                type="nginx_preset_var",
                key="http_host",
                value="$http_host"
            )
        ]
        remoteAuthRulesRemoteAuth = RemoteAuthRule(
            auth_server="https://192.168.0.0",
            request_method="GET",
            file_type_setting="all",
            reserve_args_setting="reserve_all_args",
            add_custom_args_rules=listAddCustomArgsRulesRemoteAuthRules,
            reserve_headers_setting="reserve_specific_headers",
            add_custom_headers_rules=listAddCustomHeadersRulesRemoteAuthRules,
            auth_success_status="200",
            auth_failed_status="403",
            response_status="403",
            timeout=500,
            timeout_action="pass",
            reserve_headers="sf"
        )
        remoteAuthConfigs = CommonRemoteAuth(
            remote_authentication="on",
            remote_auth_rules=remoteAuthRulesRemoteAuth
        )
        listBackSourcesFlexibleOrigin = [
            BackSources(
                sources_type="domain",
                ip_or_domain="www.back.example.com"
            )
        ]
        listFlexibleOriginConfigs = [
            FlexibleOrigins(
                match_type="file_path",
                match_pattern="/test",
                priority=1,
                back_sources=listBackSourcesFlexibleOrigin
            )
        ]
        compressConfigs = Compress(
            status="off"
        )
        forceRedirectConfigs = ForceRedirectConfig(
            status="on",
            type="http",
            redirect_code=301
        )
        refererConfigs = RefererConfig(
            type="black",
            value="192.168.0.0",
            include_empty=True
        )
        ipFilterConfigs = IpFilter(
            type="black",
            value="192.168.0.0"
        )
        listCacheRulesConfigs = [
            CacheRules(
                match_type="file_extension",
                match_value=".zip",
                ttl=0,
                ttl_unit="h",
                priority=10,
                follow_origin="off",
                url_parameter_type="del_params",
                url_parameter_value="test_param"
            )
        ]
        listSourcesConfigs = [
            SourcesConfig(
                origin_type="domain",
                origin_addr="www.example.com",
                priority=70,
                http_port=80,
                https_port=443
            )
        ]
        urlAuthConfigs = UrlAuth(
            status="off"
        )
        listHttpResponseHeaderConfigs = [
            HttpResponseHeader(
                name="test-name",
                value="test_value",
                action="set"
            )
        ]
        listOriginRequestHeaderConfigs = [
            OriginRequestHeader(
                name="test-name",
                value="test_value",
                action="set"
            )
        ]
        configsbody = Configs(
            origin_request_header=listOriginRequestHeaderConfigs,
            http_response_header=listHttpResponseHeaderConfigs,
            url_auth=urlAuthConfigs,
            sources=listSourcesConfigs,
            origin_protocol="follow",
            origin_follow302_status="off",
            cache_rules=listCacheRulesConfigs,
            ip_filter=ipFilterConfigs,
            referer=refererConfigs,
            force_redirect=forceRedirectConfigs,
            compress=compressConfigs,
            ipv6_accelerate=1,
            flexible_origin=listFlexibleOriginConfigs,
            slice_etag_status="off",
            origin_receive_timeout=30,
            remote_auth=remoteAuthConfigs,
            websocket=websocketConfigs,
            video_seek=videoSeekConfigs,
            request_limit_rules=listRequestLimitRulesConfigs,
            sni=sniConfigs,
            request_url_rewrite=listRequestUrlRewriteConfigs,
            browser_cache_rules=listBrowserCacheRulesConfigs,
            access_area_filter=listAccessAreaFilterConfigs
        )
        request.body = ModifyDomainConfigRequestBody(
            configs=configsbody
        )
        response = client.update_domain_full_config(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    cdn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := global.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := cdn.NewCdnClient(
        cdn.CdnClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateDomainFullConfigRequest{}
	enterpriseProjectIdRequest:= "<enterprise_project_id>"
	request.EnterpriseProjectId = &enterpriseProjectIdRequest
	typeAccessAreaFilter:= "black"
	contentTypeAccessAreaFilter:= "all"
	areaAccessAreaFilter:= "CN_IN,AU"
	exceptionIpAccessAreaFilter:= "0.0.0.0"
	var listAccessAreaFilterConfigs = []model.AccessAreaFilter{
        {
            Type: &typeAccessAreaFilter,
            ContentType: &contentTypeAccessAreaFilter,
            Area: &areaAccessAreaFilter,
            ExceptionIp: &exceptionIpAccessAreaFilter,
        },
    }
	matchValueCondition:= "/test/*.jpg"
	conditionBrowserCacheRules := &model.BrowserCacheRulesCondition{
		MatchType: "full_path",
		MatchValue: &matchValueCondition,
		Priority: int32(10),
	}
	ttlBrowserCacheRules:= int32(20)
	ttlUnitBrowserCacheRules:= "h"
	var listBrowserCacheRulesConfigs = []model.BrowserCacheRules{
        {
            Condition: conditionBrowserCacheRules,
            CacheType: "ttl",
            Ttl: &ttlBrowserCacheRules,
            TtlUnit: &ttlUnitBrowserCacheRules,
        },
    }
	conditionRequestUrlRewrite := &model.UrlRewriteCondition{
		MatchType: "full_path",
		MatchValue: "/test/*.jpg",
		Priority: int32(10),
	}
	redirectStatusCodeRequestUrlRewrite:= int32(301)
	redirectHostRequestUrlRewrite:= "http://www.example.com"
	var listRequestUrlRewriteConfigs = []model.RequestUrlRewrite{
        {
            Condition: conditionRequestUrlRewrite,
            RedirectStatusCode: &redirectStatusCodeRequestUrlRewrite,
            RedirectUrl: "/test/index.html",
            RedirectHost: &redirectHostRequestUrlRewrite,
            ExecutionMode: "redirect",
        },
    }
	serverNameSni:= "test.example.com"
	sniConfigs := &model.Sni{
		Status: "on",
		ServerName: &serverNameSni,
	}
	statusRequestLimitRules:= "on"
	matchValueRequestLimitRules:= "/test"
	var listRequestLimitRulesConfigs = []model.RequestLimitRules{
        {
            Status: &statusRequestLimitRules,
            Priority: int32(88),
            MatchType: "catalog",
            MatchValue: &matchValueRequestLimitRules,
            Type: "size",
            LimitRateAfter: int64(1024),
            LimitRateValue: int32(50),
        },
    }
	enableFlvByTimeSeekVideoSeek:= true
	startParameterVideoSeek:= "start"
	endParameterVideoSeek:= "end"
	videoSeekConfigs := &model.VideoSeek{
		EnableVideoSeek: true,
		EnableFlvByTimeSeek: &enableFlvByTimeSeekVideoSeek,
		StartParameter: &startParameterVideoSeek,
		EndParameter: &endParameterVideoSeek,
	}
	websocketConfigs := &model.WebSocketSeek{
		Status: "on",
		Timeout: int32(60),
	}
	var listAddCustomHeadersRulesRemoteAuthRules = []model.CustomArgs{
        {
            Type: "nginx_preset_var",
            Key: "http_host",
            Value: "$http_host",
        },
    }
	var listAddCustomArgsRulesRemoteAuthRules = []model.CustomArgs{
        {
            Type: "nginx_preset_var",
            Key: "http_host",
            Value: "$http_host",
        },
    }
	reserveHeadersRemoteAuthRules:= "sf"
	remoteAuthRulesRemoteAuth := &model.RemoteAuthRule{
		AuthServer: "https://192.168.0.0",
		RequestMethod: "GET",
		FileTypeSetting: "all",
		ReserveArgsSetting: "reserve_all_args",
		AddCustomArgsRules: &listAddCustomArgsRulesRemoteAuthRules,
		ReserveHeadersSetting: "reserve_specific_headers",
		AddCustomHeadersRules: &listAddCustomHeadersRulesRemoteAuthRules,
		AuthSuccessStatus: "200",
		AuthFailedStatus: "403",
		ResponseStatus: "403",
		Timeout: int32(500),
		TimeoutAction: "pass",
		ReserveHeaders: &reserveHeadersRemoteAuthRules,
	}
	remoteAuthConfigs := &model.CommonRemoteAuth{
		RemoteAuthentication: "on",
		RemoteAuthRules: remoteAuthRulesRemoteAuth,
	}
	var listBackSourcesFlexibleOrigin = []model.BackSources{
        {
            SourcesType: "domain",
            IpOrDomain: "www.back.example.com",
        },
    }
	var listFlexibleOriginConfigs = []model.FlexibleOrigins{
        {
            MatchType: "file_path",
            MatchPattern: "/test",
            Priority: int32(1),
            BackSources: listBackSourcesFlexibleOrigin,
        },
    }
	compressConfigs := &model.Compress{
		Status: "off",
	}
	typeForceRedirect:= "http"
	redirectCodeForceRedirect:= int32(301)
	forceRedirectConfigs := &model.ForceRedirectConfig{
		Status: "on",
		Type: &typeForceRedirect,
		RedirectCode: &redirectCodeForceRedirect,
	}
	valueReferer:= "192.168.0.0"
	includeEmptyReferer:= true
	refererConfigs := &model.RefererConfig{
		Type: "black",
		Value: &valueReferer,
		IncludeEmpty: &includeEmptyReferer,
	}
	valueIpFilter:= "192.168.0.0"
	ipFilterConfigs := &model.IpFilter{
		Type: "black",
		Value: &valueIpFilter,
	}
	matchTypeCacheRules:= "file_extension"
	matchValueCacheRules:= ".zip"
	ttlCacheRules:= int32(0)
	followOriginCacheRules:= "off"
	urlParameterTypeCacheRules:= "del_params"
	urlParameterValueCacheRules:= "test_param"
	var listCacheRulesConfigs = []model.CacheRules{
        {
            MatchType: &matchTypeCacheRules,
            MatchValue: &matchValueCacheRules,
            Ttl: &ttlCacheRules,
            TtlUnit: "h",
            Priority: int32(10),
            FollowOrigin: &followOriginCacheRules,
            UrlParameterType: &urlParameterTypeCacheRules,
            UrlParameterValue: &urlParameterValueCacheRules,
        },
    }
	httpPortSources:= int32(80)
	httpsPortSources:= int32(443)
	var listSourcesConfigs = []model.SourcesConfig{
        {
            OriginType: "domain",
            OriginAddr: "www.example.com",
            Priority: int32(70),
            HttpPort: &httpPortSources,
            HttpsPort: &httpsPortSources,
        },
    }
	urlAuthConfigs := &model.UrlAuth{
		Status: "off",
	}
	valueHttpResponseHeader:= "test_value"
	var listHttpResponseHeaderConfigs = []model.HttpResponseHeader{
        {
            Name: "test-name",
            Value: &valueHttpResponseHeader,
            Action: "set",
        },
    }
	valueOriginRequestHeader:= "test_value"
	var listOriginRequestHeaderConfigs = []model.OriginRequestHeader{
        {
            Name: "test-name",
            Value: &valueOriginRequestHeader,
            Action: "set",
        },
    }
	originProtocolConfigs:= "follow"
	originFollow302StatusConfigs:= "off"
	ipv6AccelerateConfigs:= int32(1)
	sliceEtagStatusConfigs:= "off"
	originReceiveTimeoutConfigs:= int32(30)
	configsbody := &model.Configs{
		OriginRequestHeader: &listOriginRequestHeaderConfigs,
		HttpResponseHeader: &listHttpResponseHeaderConfigs,
		UrlAuth: urlAuthConfigs,
		Sources: &listSourcesConfigs,
		OriginProtocol: &originProtocolConfigs,
		OriginFollow302Status: &originFollow302StatusConfigs,
		CacheRules: &listCacheRulesConfigs,
		IpFilter: ipFilterConfigs,
		Referer: refererConfigs,
		ForceRedirect: forceRedirectConfigs,
		Compress: compressConfigs,
		Ipv6Accelerate: &ipv6AccelerateConfigs,
		FlexibleOrigin: &listFlexibleOriginConfigs,
		SliceEtagStatus: &sliceEtagStatusConfigs,
		OriginReceiveTimeout: &originReceiveTimeoutConfigs,
		RemoteAuth: remoteAuthConfigs,
		Websocket: websocketConfigs,
		VideoSeek: videoSeekConfigs,
		RequestLimitRules: &listRequestLimitRulesConfigs,
		Sni: sniConfigs,
		RequestUrlRewrite: &listRequestUrlRewriteConfigs,
		BrowserCacheRules: &listBrowserCacheRulesConfigs,
		AccessAreaFilter: &listAccessAreaFilterConfigs,
	}
	request.Body = &model.ModifyDomainConfigRequestBody{
		Configs: configsbody,
	}
	response, err := client.UpdateDomainFullConfig(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

204

请求成功。

错误码

请参见错误码

分享:

    相关文档

    相关产品