帮助与文档

设置域名配置(内部详细版文档) 下载PDF文档

接口地址

请求URL: domain/config (POST)

接口请求域名: cdn.api.baishan.com
接口版本: v2

接口描述

对加速域名各项配置进行设置和修改,例如:缓存规则,IP黑名单,referer防盗链,源站,回源host等。

注意: 接口调用频率不超过30次/分钟。

各项配置(referer、origin、cache_rule)可以一并提交,也可以单独提交,当多个配置一起提交时,如果存在某一项配置规则不合法,那么单次提交的所有配置均无法保存。

输入参数

公有参数:用户的 token 可向值班同事获取。

请求参数(POST)

参数支持 form-data、x-www-form-urlencoded、json 等格式

参数名数据类型是否必须说明
domainsstring可传入多个域名进行批量配置,以英文逗号(,)分隔,单次不超过10个, 例如:aa.qingcdn.com,bb.qingcdn.com
configarray配置项参数, {"referer":json, "cache_rule":json}

origin (回源配置)

参数名数据类型是否必须说明
default_masterstring主回源, 可填ip, 域名, 多个以逗号(,)分隔
例如: "133.233.133.33,133.233.22.33", 主源/备源最多6个ip
default_slavestring备回源, 可填ip, 域名, 多个以逗号(,)分隔
例如: "133.233.133.33,133.233.22.33"
注:主备源不可设置为一样, 不可与主源存在重复
origin_modestring回源方式, 默认为default, 可选值有:http,https,default,custom
origin_mode=http:表示回源方式以http回源, 即http,和80端口
origin_mode=https:表示回源方式以https回源, 即https,和443端口
origin_mode=default:表示回源以用户访问协议跟随回源,
origin_mode=custom:表示回源方式以自定义回源, ori_https和port可自定义
ori_httpsstring回源是否https, 可选值: yes,no, 当origin_mode=custom时, 该值可设置
portint回源端口, 默认为空, 以80端口回源, 当origin_mode=custom时, 该值可设置(0-65535)
#回源配置
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token":"xxx",
    "domains":"example.com",
    "config": {   
        "origin": {
            "default_master":"1.1.1.1,1.1.1.2",
            "default_slave":"2.2.2.2",
            "origin_mode":"custom",
            "ori_https":"yes",
            "port":1040
        }
    }
}'

origin_host (回源HOST)

参数名数据类型是否必须说明
hoststring回源host
例如: "test.qingcdn.com",不支持IP
# 设置源站host
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token":"xxx",
    "domains":"example.com",
    "config": {   
        "origin_host": {
            "host": "www.example.com"
        }
    }
}'

referer (referer黑白名单)

参数名数据类型是否必须说明
typeint防盗链类型,
1:配置的list为黑名单,
2:配置的list为白名单
listarray黑白名单域名列表,可设置多个,以逗号分隔,最多200个,目前不支持正则;泛域名请以【*.】开头, 例如:["*.aaa.qingcdn.com", "www.qingcdn.com","*.test.com"] " *.test.com" 包括任意的匹配主机头,包括空主机头
allow_emptyboolean默认为true, true=允许referer为空也能正常访问, false=不允许referer为空访问
# 设置referer黑名单
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token":"xxx",
    "domains":"example.com",
    "config": {   
        "referer": {
            "type":"1",
            "list":[
                "*.example.com",
                "www.example2.com"
            ],
            "allow_empty":true
        }
    }
}'
# 设置referer白名单
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token":"xxx",
    "domains":"example.com",
    "config": {   
        "referer": {
            "type":"2",
            "list":[
                "*.example.com",
                "www.example2.com"
            ],
            "allow_empty":false
        }
    }
}'

cache_rule (缓存规则)

参数名数据类型是否必须说明
typeint缓存类型,
1:文件名后缀,
2:目录,
3:完整路径匹配,4:正则
patternstring缓存规则,多个以逗号分隔, 例如:
type=1时jpg,png,gif
type=2时/product/index,/test/index,/user/index
type=3时/index.html,/test/*.jpg,/user/get?index
type=4时 例子见下面说明 设置对应的正则, 设置了正则后, 对请求访问的url与正则做匹配, 匹配成功则使用该缓存规则.
默认是带参数缓存,忽略过期时间,不忽略 不缓存头
timeint缓存时间, 配合timeunit使用, 最大时间不超过2年,
当time=0时, 不对指定pattern进行缓存(即禁止缓存)
timeunitstring缓存时间单位,默认值为s, 可选值有(Y年,M月,D日,h时,i分,s秒)
ignore_no_cachestring缓存时间time大于0时有效, 忽略源站不缓存头, 默认值为off, 可选参数: on,off
ignore_expiredstring缓存时间time大于0时有效, 忽略源站过期时间, 默认值为on, 可选参数: on,off
ignore_querystring缓存时间time大于0时有效, 忽略参数缓存并且忽略参数回源, 默认值为off, 可选参数: on,off

缓存优先级说明 : 优先级按规则数组排序,由高至低排序
缓存规则正则使用说明 : 正则规则是作为一般类型无法满足情形下的补充, 使用不当会引起缓存不必要的故障, 建议有一定正则基础的开发者使用, 请理解清楚正则的使用规则后再应用到线上服务中, 设置缓存规则为正则, 会将请求的url地址(url地址:包含http/https协议部分、域名、端口[有的话]、路径、参数等几个部分)与正则去做匹配, 匹配成功则会使用该规则设定的缓存时间.

  1. 举例1: .*\.(gif|png|jpg)$, 那么他将匹配所有含(gif,png,jpg)文件名后缀的url
  2. 举例2: ^https?://[^/]+/dir1/dir2/(dir3_1|dir3_2)\.html, 该规则匹配当前域名下/dir1/dir2/dir3_1.html和/dir1/dir2/dir3_2.html规则.
# 添加缓存规则(可以为多个缓存规则)
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "cache_rule":[
            {
                "type":1,
                "pattern":"jpg,png,gif",
                "time":3600
            },
            {
                "type":1,
                "pattern":"avi,mp4,mpeg",
                "time":3600
            }
        ]
    }
}'

cache_rule_list (缓存规则新)

参数名数据类型是否必须说明
match_methodstring缓存类型,
ext:文件名后缀,
dir:目录,
route:完整路径匹配,regex:正则
patternstring缓存规则,多个以逗号分隔, 例如:
type=ext时jpg,png,gif
type=dir时/product/index,/test/index,/user/index
type=route时/index.html,/test/*.jpg,/user/get?index
type=regex时 例子见下面说明 设置对应的正则, 设置了正则后, 对请求访问的url与正则做匹配, 匹配成功则使用该缓存规则.
默认是带参数缓存,忽略过期时间,不忽略 不缓存头
case_ignorestring是否忽略大小写,yes忽略,no不忽略。默认yes
expireint缓存时间, 配合expire_unit使用, 最大时间不超过2年,
当time=0时, 不对指定pattern进行缓存(即禁止缓存)
expire_unitstring缓存时间单位,默认值为s, 可选值有(Y年,M月,D日,h时,i分,s秒)
ignore_no_cache_headersstring是否忽略源站响应头中的不缓存信息<br/>如Cache-Control:no-cache等, 默认值为no, 可选参数: no,yes
ignore_no_cache_headers=no:表示不忽略
ignore_no_cache_headers=yes:表示忽略
follow_expiredstring是否遵循源站缓存时间, 默认值为no, 可选参数: no,yes
follow_expired=no:表示不循源
follow_expired=yes:表示循源
query_params_opstring问号后参数处理方式, 默认值为do_nothing, 可选参数: do_nothing,cache_back_source_remove
do_nothing:不处理
cache_back_source_remove:缓存/回源均去除
customer:自定义,配合这部分参数进行使用query_params_op_way, query_params_op_when, params
priorityint排序值,priority值越低,优先级越高,不允许重复
cache_or_notstring是否缓存,可选值:["yes","no"],不传默认按照expire来判断是否开启缓存
query_params_op_waystring必须在query_params_op=customer才能生效,可选值:keep :保留, remove :去除
query_params_op_whenstring必须在query_params_op=customer才能生效,可选值:cache : 仅缓存时处理/缓存, cache_back_source :回源均作处理
paramsstring必须在query_params_op=customer才能生效,参数列表
# 添加缓存规则(可以为多个缓存规则)
curl -X POST "http://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token":"xxx",
    "domains":"test.aa.qingcdn.com",
    "config": {
        "cache_rule_list":[
            {
            "match_method":"dir",
            "pattern":"/www/html,/www/aaa",
            "case_ignore":"no",
            "priority":13,
            "expire":60,
            "expire_unit":"i",
            "ignore_no_cache_headers":"yes", 
            "follow_expired":"no",
            "query_params_op":"do_nothing"
            },
            {
            "match_method":"ext",
            "pattern":"php,jsp,asp,aspx",
            "case_ignore":"no",
            "priority":15,
            "expire":3600,
            "expire_unit":"s",
            "ignore_no_cache_headers":"yes", 
            "follow_expired":"no",
            "query_params_op":"cache_back_source_remove"
            }
        ]
    }
}'

ip_black_list (ip黑名单)

参数名数据类型是否必须说明
listarrayip黑名单列表,多个以逗号分隔,最多可设置200个, 例如:["1.1.1.0/24", "2.2.2.2", "3.3.3.3"]
支持/8,/16,/24格式的网段设置,网段不能存在交叉重复, 注意: 黑白名单只能同时存在一种, 设置了黑名单, 白名单将被清除
modestringappend:追加模式
cover:覆盖模式,默认cover
# 设置ip黑名单
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token":"xxx",
    "domains":"example.com",
    "config": {   
        "ip_black_list": {
            "list": [
                "14.12.11.0/24",
                "1.2.3.4"
            ],
            "mode": "cover"
        }
    }
}'

ip_white_list (ip白名单)

参数名数据类型是否必须说明
listarrayip白名单列表,多个以逗号分隔,最多可设置200个, 例如:["1.1.1.0/24", "2.2.2.2", "3.3.3.3"]
支持/8,/16,/24格式的网段设置,网段不能存在交叉重复, 注意: 黑白名单只能同时存在一种, 设置了白名单, 黑名单将被清除
modestringappend:追加模式
cover:覆盖模式,默认cover
# 设置ip黑名单
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token":"xxx",
    "domains":"example.com",
    "config": {   
        "ip_white_list": {
            "list": [
                "14.12.11.0/24",
                "1.2.3.4"
            ],
            "mode": "cover"
        }
    }
}'

add_response_head (添加响应头)

参数名数据类型是否必须说明
typestring不传该参数时, 默认为reset, 可选值: reset,add,remove, reset表示清空之前的头, 重置为本次设置的值; add表示新增一个响应头, 存在则覆盖, remove表示删除响应头(参数于add,reset有所差异))
listarray响应头列表: type为reset和add时, 如: [{"name":"Content-Type","value":"text/html.."},{"name":"Cache-Control","value":"max-age..."}], type为remove时, 只需传入头的名称, 如 ["Content-Type","Cache-Control"]
#添加响应头
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "add_response_head": {
            "type":"add",
            "list":[
                {
                    "name":"Content-Type", 
                    "value":"text/html; charset=ISO-8859-4"
                },
                {
                    "name":"Cache-Control", 
                    "value":"max-age=300, must-revalidate"
                }
            ]
        }
    }
}'

#删除响应头
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "add_response_head": {
            "type":"remove",
            "list":["Content-Type","Cache-Control"]
        }
    }
}'

add_back_source_head (添加回源请求头)

参数名数据类型是否必须说明
head_namestring回源请求头的名称,最多可以添加20个。
head_valuestring回源请求头的值
write_when_existsstring若存在相同请求头时是否覆盖
yes:覆盖
no:不覆盖
不填充时,默认值为yes。
#添加回源请求头
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"example.com",
    "config": {
        "add_back_source_head":[
            {
                "head_name":"name",
                "head_value":"value1",
                "write_when_exists":"yes"
            },
            {
                "head_name":"name2",
                "head_value":"value2",
                "write_when_exists":"no"
            }
        ]
    }
}'

https (证书配置)

参数名数据类型是否必须说明
cert_idint证书ID, 注意: 当设置为0时, 可解除证书绑定并降级为http
http2string可选值:on、off, on=开启http2, off=关闭http2
force_httpsinteger是否强制跳转为https, 0:否(默认), 302:以状态码=302的方式跳转, 301:以状态码=301的方式跳转
ocspstringOCSP[on,off]
不填时不作变更
ssl_protocolstring[]值范围:["TLSv1","TLSv1.1","TLSv1.2","TLSv1.3"]
# 设置https证书
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token":"xxx",
    "domains":"example.com",
    "config": {
        "https": {
            "cert_id": 10101,
            "http2":"on",
            "force_https":"301",
            "ocsp": "on"
        }
    }
}'

visit_timestamp (时间戳防盗链)

参数名数据类型是否必须说明
patternstring匹配url的正则表达式, url格式为$scheme://$domain/$uri?$args, 正则应按需要匹配的url进行设置, 例如.*, 匹配所有访问的url地址
time_formatstring时间格式, 可选值有timestamp_hex(16进制时间戳), date_minute(日期, 格式为YYYYmmddHHii, 例如201805211010), timestamp(十进制时间戳),
keystring参与生成签名的秘钥, 多个用空格分隔
deadtimeinturl的存活时间, 例如3600, 参数要求大于0, 单位为秒(s), 超过该时间则认为是无效的url链接
req_uri_typeinturl的匹配模式, 目前共4中url模式:
1: $scheme://$domain/$uri?$args&{keyname}=$key&{timename}=$time&$args
2: $scheme://$domain/$uri?$args&{timename}=$time&{keyname}=$key&$args
3: $scheme://$domain/$time/$key/$uri?$args
4: $scheme://$domain/$key/$time/$uri?$args
origin_typeint回源方式是否带参数, 可选值有1,2, 默认为1, 1表示不带加密串回源,2:带加密串回源
stylestring参数加密的排序组合, $ourkey$uri$time, 更换排序可更换($ourkey,$uri,$time)三个变量的顺序, 暂不支持加入额外的字段和信息
timenamestring默认值为time, 在url中传参用的参数名, 仅通过?传参时需要
keynamestring默认值为key, 将(path,key,time)用md5生成签名, 通过参数名在url中传递

时间戳防盗链: 在查询配置或创建成功后返回的参数中有request_style, 表示根据时间戳防盗链相关的参数进行配置后, 生成的匹配规则, 供参考用.

forbid_httpx (禁止http或https访问)

参数名数据类型是否必须说明
protocolstring禁止访问的协议,可选值为http,https

cache_error_code (错误状态码缓存)

参数名数据类型是否必须说明
bcachestring是否开启缓存,可选值为on,off
codearray状态码列表,可设置多个,以逗号分隔,可选值为400,403,404,414,500,501,502,503,504,506,5xx, 其中5xx包括500,501,502,503,504,506
例如:["400","403","5xx"]
cache_timestring缓存时间, 配合cache_unit使用, 最大时间不超过2年,
注意:bcache=on时,该参数必传
cache_unitstring缓存时间单位, 可选值有(year:年,month月,day:日,hour:时,minute:分,second:秒)
注意:bcache=on时,该参数必传

video_drag (视频拖拉)

参数名数据类型是否必须说明
urlstring匹配的url规则, 例如: \.(mp4flvf4vm4v)
mp4string是否开启mp4拖拉, 可选值: on/off
flvstring是否开启flv拖拉, 可选值: on/off
startstring开始参数, 例如: start, 参数名允许字符为: '字母,数字,下划线, 且不能为数字开头'
endstring结束参数, 例如: end, 参数名允许字符为: '字母,数字,下划线, 且不能为数字开头'

compress_response (压缩响应)

参数名数据类型是否必须说明
content_typearray对应的头, 例如: ["text/plain","application/x-javascript"]
min_sizeint最小尺寸, 例如: 2, 该参数与min_size_unit配合使用, 表示最小多大尺寸的文件开始压缩
min_size_unitstring最小尺寸单位, 例如: KB, 可选值有: KB/MB

speed_limit(单链接限速)

参数名数据类型是否必须说明
typestringURL匹配类型,
ext:文件名后缀,
dir:目录,
route:完整路径匹配,
regex:正则,
all: 所有
patternstringurl匹配规则,多个以逗号分隔, 例如:
type=all时:只支持.*
type=ext时:jpg,png,gif
type=dir时:/product/index,/test/index,/user/index
type=route时:/index.html,/test/*.jpg,/user/get?index
type=regex时: 例子见下面说明 设置对应的正则, 设置了正则后, 对请求访问的url与正则做匹配, 匹配成功则使用该限速规则.
speedstring限速值,单位 Kbps,实际生效会转换为 KB
begin_timestring限速生效开始时间,形如 HH:ii,比如( 08:30 )24小时制
end_timestring限速生效结束时间,形如 HH:ii,比如( 08:30 )24小时制

配置生效方式:覆盖式更新

规则总数:最多只能有100条规则。

限速时间:结束时间必须大于开始时间

限速值:会转换为 KB,并向上取整,比如填入 12 kbps,则生效的限速值为 2KB

URL匹配正则使用说明 : 正则规则是作为一般类型无法满足情形下的补充, 使用不当会引起限速规则不必要的故障, 建议有一定正则基础的开发者使用, 请理解清楚正则的使用规则后再应用到线上服务中, 设置URL匹配规则为正则, 会将请求的url地址(url地址:包含http/https协议部分、域名、端口[有的话]、路径、参数等几个部分)与正则去做匹配, 匹配成功则会使用该规则设定的限速规则.

  1. 举例1: .*\.(gif|png|jpg)$, 那么他将匹配所有含(gif,png,jpg)文件名后缀的url
  2. 举例2: ^https?://[^/]+/dir1/dir2/(dir3_1|dir3_2)\.html, 该规则匹配当前域名下/dir1/dir2/dir3_1.html和/dir1/dir2/dir3_2.html规则.
#添加单链接限速
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "speed_limit": [
            {
                "type":"ext",
                "speed":"80",
                "begin_time":"12:00",
                "end_time":"13:00",
                "pattern":"jpg"
            }
        ]
    }
}'

visit_deny_whitelist (防盗链白名单)

参数名数据类型是否必须说明
urlstring必填项,设置url路径:/user/get?index
turn_onboolean可选值:true、false, true=开启当前url白名单, false=去除当前url防盗链白名单设置
#添加防盗链白名单
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "visit_deny_whitelist": [
            {"url":"/user/get?index","turn_on":true},
            {"url":"/contract/get?index","turn_on":true}
        ]
    }
}'

#删除防盗链白名单
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "visit_deny_whitelist": [
            {"url":"/user/get?index","turn_on":false},
            {"url":"/contract/get?index","turn_on":false}
        ]
    }
}'

防盗链白名单设置成功后会输出对应设置成功后的配置参数

{
    "code": 0,//0操作成功, 非0时会给出对应的错误提示
    "data": {
        "config": {
            "visit_deny_whitelist": {
                "url": [
                "/user/get?index",
                "/contract/get?index"
                ]
            },
            ...
        }
    }
}

range_back_source (分片回源 )

参数名数据类型是否必须说明
-string默认开启分片回源,配置off关闭分片回源。备注:配置on在域名详情不展示,配置off可以在域名详情展示
curl -X POST "http://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token":"xx",
    "domains":"aa.qingcdn.com",
    "config": {
        "range_back_source":"off"
    }
}'

extend (Squid扩展配置)

参数名数据类型是否必须说明
squidstring必填项,squid扩展配置,使用rn换行
#Squid扩展配置
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "extend":{
            "squid":"acl url_host url_regex -i ^https?://[^/]+/[^/]*c_scale.*\r\ncache_peer_access xuntiku-static allow !url_host"
        }
    }
}'

rate_limit (限速)

参数名数据类型是否必须说明
max_rate_countint必填项,限速值
leading_flow_countint非必填,前面多少字节不限速
leading_flow_unitstring非必填,前面多少字节不限速单位,值范围:[KB,MB],默认MB
max_rate_unitstring非必填,限速单位,值范围:[KB,MB],默认MB
#Squid扩展配置
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "rate_limit": {
            "max_rate_count":10
        }
    }
}'

new_origin (域名源(新))

参数名数据类型是否必须说明
originstring必填项,源站地址
portint非必填,回源端口,不填时根据protocol参数来决定,protocol=http时,port=80;protocol=https时,port=443;protocol=default时,port传入值不生效,固定为0,参数范围(0,65535)
protocolstring非必填,回源协议;可选值[default,http,https];默认值default;default:遵循请求端口和请求协议回源(请求xx端口则回源xx端口,请求https协议回源走https协议);http:回源固定走http协议;https:回源固定走https协议
hoststring非必填,回源host;默认值"",需要为域名格式;当没有设置回源host时,回源host头部会和加速域名一致
levelint非必填,主备等级,数值越大优先级越大;可选值[10,20];默认值"20";注:当多个源站主备等级一致时,则均为主源,如果多个源站主备等级不同,则数值最大的为主源,其余的为备源,且备源的主备等级数值越大优先级越高;例如某加速域名设置了4个回源IP,A和B主备等级均为20,C的主备等级为15,D的主备等级为10,则在A和B源正常时,优先回AB源,当A和B均异常时,优先回C源,ABC均异常时,回D源
weight_levelint非必填,权重等级;可选值[1,10000];默认值"1";注:权重等级数值越高,权重越大,当主备等级一致时,会根据权重比例回源;例如:某加速域名设置了2个源站,A源和B源主备等级均为20,A源权重等级为60,B源权重等级为40,则A源的回源请求数约为该域名总回源请求数的60%,B源的回源请求数约为该域名总回源请求数的40%
ispstring非必填,运营商,指定运营商回源;可选值[default.dx.lt.yd];默认值"default";注:当设置了该项配置时,默认源"default"值必须设置;例如某加速域名设置了电信源A,则必须设置默认源B,指定电信请求回到A源站,其他请求回到B源站;
connect_timeint非必填,TCP建联时间,TCP建联时间指 回源时的TCP建联超时时间,默认15秒, 可设置3~60秒之间的正整数

特殊说明 :

1.和域名源/回源HOST 子服务和此子服务配置存在冲突,该子服务的优先级更高
2.当host配置为空且配置有回源HOST有配置时,以回源HOST为准
3.该子服务优先级低于拓展配置
4.配置是覆盖模式,当前不支持追加

curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token": "xxx",
    "domains": "aa.qingcdn.com",
    "config": {
        "new_origin": [
            {
                "origin": "1.1.1.1",
                "port": 80,
                "protocol": "http",
                "host": "example.com",
                "level": 20,
                "weight_level": 1,
                "isp": "default"
            }
        ]
    }
}'

cache_share (共用缓存)

参数名数据类型是否必须说明
share_waystring必填项,共用方式,值范围:[inner_share,cross_single_share,cross_all_share]
inner_share:本域名内HTTP、HTTPS共用缓存;
cross_single_share:不同域名间HTTP、HTTPS分别共用缓存
cross_all_share:不同域名间HTTP、HTTPS全部共用缓存
domainstring必填项,待共享的域名share_waycross_single_sharecross_all_share此项才生效
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "cache_share": {
              "share_way": "cross_single_share",
              "domain": "bb.qingcdn.com"
        }
    }
}'

head_control (HTTP头控制)

参数名数据类型是否必须说明
regexstring必填项,匹配的url
head_opstring必填项,操作内容,值范围:[ADD,DEL,ALT];
ADD:增加;
DEL:删除;
ALT:修改;
head_directionstring必填项,方向,值范围:[CLI_REQ,CLI_REP,SER_REQ,SER_REP];
CLI_REQ:客户端请求头;
CLI_REP:客户端响应头;
SER_REQ:回源请求头;
SER_REP:源响应头;
headstring必填项,HTTP头名称
valuestring必填项(head_op = DEL时为非必填,其余为必填),头部值
orderint必填项,优先级
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "head_control": {
            "list": [
                {
                    "regex": ".*",
                    "head_op": "ADD",
                    "head_direction": "CLI_REQ",
                    "head": "test_header",
                    "value": "X-test",
                    "order": 1
                }
            ]
        }
    }
}'

timeout (回源读超时时间)

参数名数据类型是否必须说明
timestring必填项,超时时间,单位s,值范围:[5-300]
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "timeout": {
              "time": "6"
        }
    }
}'

connect_timeout (回源建联超时时间)

参数名数据类型是否必须说明
origin_connect_timeoutstring必填项,回源建联超时时间,单位s,值范围:[5-60]
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
        "connect_timeout": {
              "origin_connect_timeout": "10"
        }
    }
}'

qiniu_origin_auth (七牛回源鉴权)

参数名数据类型是否必须说明
auth_urlstring仅支持http协议开头的url,例如http://test.com/
match_methodstring默认【default】,【default】所有,【ext】仅匹配对应后缀,【regex】仅匹配正则内容
patternstring默认为空匹配所有,match_method=ext时,必填后缀逗号,隔开,match_method=regex时,必填正则匹配
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"test.com",
    "config": {
        "qiniu_origin_auth": {
            "auth_url": "http://test.com/",
            "match_method": "ext",
            "pattern": "jpg,web,html"
        }
    }
}'

forward_status (继续取跳转后内容)

参数名数据类型是否必须说明
codesarray继续跳转的参数类型;
301:301跳转;302:302跳转
301和302为int类型
# 添加继续取跳转后内容
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com",
    "config": {
            "forward_status" : {
            "codes": [
                301,
                302
            ]
        }
    }
}'

cache_error_code (错误状态码缓存)

参数名数据类型是否必须说明
codearray需要缓存的错误状态码;
可选值:400、403、404、414、500、501、502、503、504、506、5XX,均为string类型
bcachestring是否需要缓存;
不缓存:off,缓存:on
cache_timeint缓存的单位时间,可选范围1-65535;注意,在bcache为on时,此参数必填
cache_unitstring缓存的单位, 可选值有(year:年,month月,day:日,hour:时,minute:分,second:秒);注意,在bcache为on时,此参数必填
# 错误状态码缓存
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token": "xxx",
    "domains": "aa.qingcdn.com",
    "config": {
        "cache_error_code" : {
            "code": [
                "403"
            ],
            "bcache": "off"
        }
    }
}'

调用示例

curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
    -H "Content-Type: application/json"\
    -d '{
    "token":"xxx",
    "domains":"aa.qingcdn.com,bb.qingcdn.com",
    "config": {
        "origin": {
            "default_master": "133.233.133.33",
            "default_slave": "12.13.41.21"
        },
        "origin_host": {
            "host": "test.qingcdn.com"
        },
        "referer": {
            "type": 1,
            "list": [
                "*.qingcdn.com",
                "new.vx.qingcdn.com"
            ],
            "allow_empty": false
        },
        "ip_black_list": {
            "list": [
                "14.12.11.0/24",
                "1.2.3.1"
            ]
        },
        "ip_white_list": {
            "list": [
                "14.12.11.0/24",
                "1.2.3.1"
            ]
        },
        "add_response_head":{
            "type":"add",
            "list":[
                {
                    "name":"Content-Type", 
                    "value":"text/html; charset=ISO-8859-4"
                },
                {
                    "name":"Cache-Control", 
                    "value":"max-age=300, must-revalidate"
                }
            ]
        },
        "https":{
            "cert_id":123
        },
        "visit_timestamp": {
            "pattern": ".*",
            "time_format": "timestamp",
            "key": "c3RyaWN0b",
            "keyname": "sign",
            "timename": "time",
            "deadtime": "3600",
            "req_uri_type": "2",
            "origin_type": "2",
            "error_page": "",
            "style": "$ourkey$uri$time"
        },
        "cache_rule": [
            {
                "type": "2",
                "pattern": "/product/index,/test/index,/user/index",
                "time": 86400,
                "timeunit": "s"
            },
            {
                "type": "1",
                "pattern": "jpg,png,gif",
                "time": 86400,
                "timeunit": "s"
            },
            {
                "type": "3",
                "pattern": "/index.html,/test/*.jpg,/user/get?index",
                "time": 86400,
                "timeunit": "s"
            }
        ],
        "video_drag": {
            "url": "\\.(mp4|flv|f4v|m4v)",
            "mp4": "off",
            "flv": "off",
            "start": "start",
            "end": "end"
        },
        "compress_response": {
            "content_type": [
                "text/plain",
                "application/x-javascript"
            ],
            "min_size": "2",
            "min_size_unit": "KB"
        }
    }
}'

返回示例

JSON格式(请求时传对应的参数, 设置成功后会输出对应设置成功后的配置参数)

{
    "code": 0,//0操作成功, 非0时会给出对应的错误提示
    "data": {
        "config": {
            "origin": {
                "default_master": "133.233.133.33",
                "default_slave": "12.13.41.21"
            },
            ...
        }
    }
}

error_page_rewrite (自定义错误页面)

参数名数据类型是否必须说明
error_status_codeint错误状态码,取值范围为400<=x<=599
redirect_status_codeint重定向状态码,取值范围为301,302
redirect_urlstring重定向URL,必须使用,http://https:// 开头,并且符合URL的格式

调用示例

curl -X POST 'http://cdn.api.baishan.com/v2/domain/config' \
--header 'content-type: application/json' \
-d '{
    "domains": "a.baishan.com",
    "token": "xxxxxx",
    "config": {
        "error_page_rewrite": [
            {
                "error_status_code": 400,
                "redirect_url": "http://a.baishan.com/err.html",
                "redirect_status_code": 301
            }
        ]
    }
}'

post_upload_size_limit (post上传大小限制)

参数名数据类型是否必须说明
limit_valueint限制大小值,取值范围为1<=x<=1024,单位M

调用示例

curl -X POST 'http://cdn.api.baishan.com/v2/domain/config' \
--header 'content-type: application/json' \
-d '{
    "domains": "a.baishan.com",
    "token": "xxxxxx",
    "config": {
        "post_upload_size_limit": {
            "limit_value": 30
        }
    }
}'

source_url_rewrite (回源URL改写)

参数名数据类型是否必须说明
origin_urlstring改写前的原始Path 正则表达式。注:以/开头,匹配原始的客户端访问路径+请求参数,并且需要使用正则表达式(例如:/test/a.jpg?a=1),正则相关特殊字符可以使用进行转义。同时,您可以在正则表达式中指定组,组是由 () 包裹的。这些组可以在目标回源路径中使用$n引用。例如,/aaa/bbb/(.*) 表示路径/aaa/bbb/下的所有目录和文件。该例子包含了一个组。
target_urlstring改写后的目标Path 正则表达式。注:以/开头,包含回源路径+请求参数,(例如:/newtest/b.jpg?a=1)。举例:待重写回源路径设置为/test/(.)/(.).jpg,目标回源路径设置为/newtest/$1/$2.apk,则用户访问请求的回源路径为/test/a/b.jpg时,根据$1将捕获第一个正则括号内的内容,即为a;$2将捕获第二个正则括号内的内容,即为b,则实际回源路径将被改写为/newtest/a/b.apk。

调用示例

curl -X POST 'http://cdn.api.baishan.com/v2/domain/config' \
--header 'content-type: application/json' \
-d '{
    "domains": "a.baishan.com",
    "token": "xxxxxx",
        "config": {
        "source_url_rewrite": [
            {
                "origin_url": "/aaa/(*).html",
                "target_url": "/bbb/$1"
            }
        ]
    }
}'

combined_ban (Combined-Ban组合封禁)

备注:combined_ban [] 里面 每一个{} 表示一条规则,configs 里面 每个封禁类型配置 对应组合的封装项

参数名数据类型是否必须说明
actionstring组合封禁方式,默认:封禁 ban,注当前只支持封禁ban方式
configsarray规则组配置信息key
* method(例配置method 请求方式封禁)string封禁类型key,当前只支持 method、ip、referer、url、ua
is_matchstring所有封禁类型都支持,是否匹配,不匹配则按非范围处理,默认:yes,可选:yes,no
case_insensitivestring仅封禁类型(ua、url)支持,区分大小写,默认:区分 yes,可选:区分 yes,不区分 no
method_typestring是(封禁类型为method必填)http请求方式,默认:get,可选:get,post
liststring是(封禁类型为ip、referer、url、ua必填)名单列表, 支持正则表达式,传入的内容默认是模糊匹配,精确匹配需要加上^$ 如: ^test\-yp$

组合封禁优先级说明 : 优先级按规则数组排序,由高至低排序

组合封禁类型说明 : 一组{}规则,configs里面的method、ip、referer、url、ua,封禁类型不能重复

组合封禁规则名单列表使用说明 :

1.ip列表 正常的IP地址,支持/8/16/24格式的网段设置,网段不能存在交叉重复.

例如: ["1.1.1.0/24", "2.2.2.2", "3.3.3.3"]

2.referer列表,默认模糊匹配,不区分大小写.

例如: ["*.aaa.qingcdn.com", "www.qingcdn.com","*.test.com"]

3.url列表,支持正则表达式,传入的内容默认是模糊匹配,精确匹配需要加上^$

例如:

模糊匹配:http://.www.ttt1.com/1.txt

精确匹配:^https?://[^/]+/dir1/dir2/(dir3_1|dir3_2).html$

该规则匹配当前域名下/dir1/dir2/dir3_1.html和/dir1/dir2/dir3_2.html规则.

4.ua列表,传入的内容默认是模糊匹配,精确匹配需要加上^$ 。

例如: 模糊匹配: test-yp, 精确匹配: ^test-yp$

输入示例

{
    "domains": "testxx.xxx.com",
    "config": {
        "combined_ban": [
          //第一条规则 配置ua、url、referer组合封禁
            {
                "action": "ban",
                "configs": {
                    "ua": {
                        "is_match": "yes",
                        "case_insensitive": "yes",
                        "list": [
                            "^test\\-yp$",
                            "test\\.com"
                        ]
                    },
                    "url": {
                        "is_match": "yes",
                        "case_insensitive": "yes",
                        "list": [
                            "^http://.www.ttt1.com/1.txt",
                            "http://.www.ttt2.com/2.txt",
                            "^http://[^/]+www.ttt2.com/2.txt"
                        ]
                    },
                    "referer": {
                        "is_match": "no",
                        "list": [
                            "www.baidu.com",
                            "test.test.com"
                        ]
                    }
                }
            },
            //第二条规则 method(请求方式)、ip组合封禁
            {
                "action": "ban",
                "configs": {
                    "method": {
                        "is_match": "yes",
                        "method_type": "post"
                    },
                    "ip": {
                        "is_match": "yes",
                        "list": [
                            "2.2.2.2",
                            "1.1.1.1"
                        ]
                    }
                }
            },
            //第二条规则 method(请求方式)组合封禁
            {
                "action": "ban",
                "configs": {
                    "method": {
                        "is_match": "no",
                        "method_type": "get"
                    }
                }
            }
        ]
    }
}

返回示例

JSON格式(请求时传对应的参数, 设置成功后会输出对应设置成功后的配置参数)

备注:combined_ban [] 里面 每一个{} 表示一条规则,configs 里面 每个封禁类型配置 对应组合的封装项

{
    "code": 0,//0操作成功, 非0时会给出对应的错误提示
    "domains": [
            {
                "id": "310649",
                "domain": "testxx.xxx.com"
            }
        ],
    "data": {
        "config": {
            "combined_ban": [
              //第一条规则
                {
                    "action": "ban",
                    "configs": {
                        "ua": {
                            "is_match": "yes",
                            "case_insensitive": "yes",
                            "list": [
                                "^test\\-yp$",
                                "test\\.com"
                            ]
                        },
                        "referer": {
                            "is_match": "no",
                            "list": [
                                "www.baidu.com",
                                "test.test.com"
                            ]
                        },
                        "url": {
                            "is_match": "yes",
                            "case_insensitive": "yes",
                            "list": [
                                "^http://.www.ttt1.com/1.txt",
                                "http://.www.ttt2.com/2.txt",
                                "^http://[^/]+www.ttt2.com/2.txt"
                            ]
                        }
                    }
                },
                //第二条规则
                {
                    "action": "ban",
                    "configs": {
                        "ip": {
                            "is_match": "yes",
                            "list": [
                                "2.2.2.2",
                                "1.1.1.1"
                            ]
                        },
                        "method": {
                            "is_match": "yes",
                            "method_type": "post"
                        }
                    }
                },
                //第三条规则
                {
                    "action": "ban",
                    "configs": {
                        "method": {
                            "is_match": "no",
                            "method_type": "get"
                        }
                    }
                }
            ]
        }
    }
}

deny_url (屏蔽非法URL)

参数名数据类型是否必须说明
urlsstring[]封禁的URL列表

调用示例

curl -X POST 'http://cdn.api.baishan.com/v2/domain/config' \
--header 'content-type: application/json' \
-d '{
    "domains": "a.baishan.com",
    "token": "xxxxxx",
        "config": {
           "deny_url": {
             "urls": [
                "http://www.test.com/5.txt",
                "^http://[^/]+www.ttt2.com/2.txt",
                "^https?://[^/]+/test1/test2\\?cd=sad($|\\?)"
            ]
        }
    }
}'

返回示例

JSON格式(请求时传对应的参数, 设置成功后会输出对应设置成功后的配置参数)

{
    "code": 0,
    "data": {
        "domains": [
            {
                "id": "123",
                "domain": "a.baishan.com"
            }
        ],
        "config": {
            "deny_url": {
                "urls": [
                    "http://www.test.com/5.txt",
                    "^http://[^/]+www.ttt2.com/2.txt",
                    "^https?://[^/]+/test1/test2\\?cd=sad($|\\?)"
                ]
            }
        }
    }
}

tos_origin (tos域名源)

参数名数据类型是否必须说明
ispstring运营商,必须默认运营商default,可选范围:【default,dx,lt,yd】
ipsstring[]回源,可配置ip或者域名,注:同一条配置[]回源类型只能一种
group_sortint主备顺序,取值范围1~10
weightint权重,取值范围1~10000
origin_modestring回源模式默认default,可选范围:【default,http,https,custom】,注:选custom可自定义回源协议和端口
protocolstring回源协议
portint回源端口
host_modestring回源host模式默认default, 可选范围:【default,custom】,注:选custom可自定义回源host
hoststring回源host
auth_typestring鉴权类型默认default无鉴权, 可选范围:【default,oss,tos】,注:选oss可配置【auth_bucket_name】,选tos可配置【auth_expire,auth_cdn_tag】, 鉴权通用参数auth_secret_key,auth_access_key
auth_secret_keystringsecret_key秘钥
auth_access_keystringaccess_key秘钥
auth_bucket_namestringbucket_name存储桶名
auth_expireintexpire过期时间,如:300 五分钟到期
auth_cdn_tagstringcdn_tag标识
parse_prioritystring源站优先解析设置默认default,可选范围:【default,v4,v4v6,v6v4,v6】,注:v4v6表示先v4后v6

调用示例

curl -X POST 'https://cdn.portal.baishan.com/v2/domain/config?token=xxx' \
--header 'Content-Type: application/json' \
-d '{
    "domains": "www.test.com",
    "config": {
        "tos_origin": [
            {//第一条
                "isp": "default",
                "group_sort": 3,
                "ips": [
                    "www.text1.com",
                    "www.text2.com"
                ],
                "origin_mode": "default"
            },
            {//第二条
                "isp": "default",
                "port": 443456,
                "group_sort": 1,
                "weight": 1000,
                "auth_expire": 600,
                "ips": [
                    "1.1.1.1"
                ],
                "protocol": "httpsav",
                "host": "www.test.com",
                "auth_bucket_name": "",
                "auth_secret_key": "xxx",
                "auth_access_key": "xxx",
                "auth_cdn_tag": "xxxx",
                "origin_mode": "custom",
                "host_mode": "custom",
                "auth_type": "tos",
                "parse_priority": "v4v6"
            }
        ]
    }
}'

返回示例

{
    "code": 0,
    "data": {
        "domains": [
            {
                "id": "56784",
                "domain": "www.test.com"
            }
        ],
        "config": {
            "tos_origin": [
                {//第一条
                    "isp": "default",
                    "group_sort": 3,
                    "ips": [
                        "www.text1.com",
                        "www.text2.com"
                    ],
                    "origin_mode": "default"
                },
                {//第二条
                    "isp": "default",
                    "port": 443456,
                    "group_sort": 1,
                    "weight": 1000,
                    "auth_expire": 600,
                    "ips": [
                        "1.1.1.1"
                    ],
                    "protocol": "httpsav",
                    "host": "www.test.com",
                    "auth_bucket_name": "",
                    "auth_secret_key": "xxx",
                    "auth_access_key": "xxx",
                    "auth_cdn_tag": "xxxx",
                    "origin_mode": "custom",
                    "host_mode": "custom",
                    "auth_type": "tos",
                    "parse_priority": "v4v6"
                }
            ]
        }
    }
}

client_real_ip (客户端真实ip)

参数名数据类型是否必须说明
headstring客户端真实ip头

调用示例

curl -X POST 'https://cdn.portal.baishan.com/v2/domain/config?token=xxx' \
--header 'Content-Type: application/json' \
-d '{
    "token": "{{token}}",
    "domains": "www.example.com",
    "config": {
        "client_real_ip": {
            "head":"xxx-xxx-xxx"
        }
    }
}'

user_agent (User-Agent黑白名单)

参数名数据类型是否必须说明
ua_liststringUser-Agent列表
url_patternstringURL规则
url_case_insensitivestringURL忽略大小写,值范围["yes", "no"]
allow_empty_uastring允许空User-Agent,值范围["yes", "no"]
ua_case_insensitivestringUser-Agent忽略大小写,值范围['yes', 'no']
url_match_typestringURL匹配类型,值范围['all'(所有), 'ext'(后缀), 'dir'(目录), 'route'(路径), 'regex'(正则)]
ua_typestringUser-Agent黑白名单类型,值范围["black"(UA黑名单模式), "white"(UA白名单模式)]
ua_match_typestringUser-Agent匹配模式,值范围["pattern"(模糊匹配), "exact"(精确匹配)]

调用示例:

curl -X POST 'https://cdn.portal.baishan.com/v2/domain/config?token=xxx' \
--header 'Content-Type: application/json' \
-d '{
    "token": "{{token}}",
    "domains": "www.example.com",
    "config": {
        "user_agent": {
            "ua_type": "black",
            "allow_empty_ua": "no",
            "ua_match_type": "pattern",
            "ua_list": "curl\nCurl\nwget\nWget\ngo\nGo",
            "ua_case_insensitive": "yes",
            "url_case_insensitive": "yes",
            "url_match_type": "all",
            "url_pattern": ".*"
        }
    }
}'

响应示例:

{
    "code": 0,
    "data": {
        "domains": [
            {
                "id": "1",
                "domain": "www.example.com"
            }
        ],
        "config": {
            "user_agent": {
                "ua_list": "curl\nCurl\nwget\nWget\ngo\nGo",
                "url_pattern": ".*",
                "url_case_insensitive": "yes",
                "allow_empty_ua": "no",
                "ua_case_insensitive": "yes",
                "url_match_type": "all",
                "ua_type": "black",
                "ua_match_type": "pattern"
            }
        }
    }
}

visit_areas_limit (访问区域黑白名单)

参数名数据类型是否必须说明
limit_typestring限制类型:
white:白名单
black:黑名单
country_liststring国家列表,多个国家用英文逗号隔开(,):
china:中国
republic of korea:韩国
viet nam:越南
thailand:泰国
japan:日本
india:印度
singapore:新加坡
indonesia:印度尼西亚
malaysia:马来西亚
bahrain:巴林
iran:伊朗
iraq:伊拉克
qatar:卡塔尔
cambodia:柬埔寨
saudi arabia:沙特阿拉伯
kuwait:科威特
pakistan:巴基斯坦
myanmar:缅甸
united arab emirates:阿联酋
philippines:菲律宾
turkey:土耳其
bangladesh:孟加拉国
laos:老挝
italy:意大利
russian federation:俄罗斯
spain:西班牙
germany:德国
france:法国
netherlands:荷兰
united kingdom:英国
brazil:巴西
colombia:哥伦比亚
nigeria:尼日利亚
egypt:埃及
south africa:南非
australia:澳大利亚
mexico:墨西哥
united states:美国
# 访问区域黑白名单
curl -X POST "https://cdn.api.baishan.com/v2/domain/config"\
  -H 'content-type: application/json' \
  -d '{
    "token": "xxx",
    "domains": "aa.qingcdn.com",
    "config": {
        "visit_areas_limit" : {
            "limit_type": "white",
            "country_list": "china"
        }
    }
}'

响应(Response Header)

HTTP/1.0 200 OK
Api-Id: 221328331
Content-Type: application/json; charset=utf-8
X-Ratelimit-Grad: minute   //接口调用频率限制粒度(分/小时/天)
X-Ratelimit-Limit: 50      //当前每分钟请求次数上限
X-Ratelimit-Remaining: 29  //每分钟剩余请求次数
X-Retry-After: 43          //xx秒后重置当前粒度(分/小时/天)请求次数限制

http状态码说明

错误状态码说明
404您输入的 URL 错误
401鉴权错误,您的token错误,或者没有开通接口权限
400请求参数有误
200执行成功,返回请求的数据
5xx请联系值班同事
CopyRight © 2015-2025 BaishanCloud . All Rights Reserved.