创建域名模板
功能介绍
创建域名模板。
调用方法
请参见如何调用API。
URI
POST /v1.0/cdn/configuration/templates
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
tml_name |
是 |
String |
参数解释: 域名模板名称 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
remark |
否 |
String |
参数解释: 域名模板描述 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
configs |
是 |
TemplateConfigs object |
参数解释: 域名模板配置 约束限制: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
http_response_header |
否 |
Array of HttpResponseHeader objects |
http响应头设置 |
cache_rules |
否 |
Array of CacheRules objects |
|
origin_follow302_status |
否 |
String |
参数解释: 开启回源跟随,当源站地址因业务需求做了301/302 重定向,CDN节点会先跳转到301/302对应地址获取资源,缓存后再返回给用户 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
compress |
否 |
Compress object |
参数解释: 智能压缩,压缩网站的静态资源,缩小传输文件的大小,提升传输效率,减少带宽消耗 约束限制: 不涉及 |
origin_range_status |
否 |
String |
参数解释: Range回源,开启后,源站在收到CDN节点回源请求时,根据HTTP请求头中的Range信息返回指定范围的数据给CDN节点 约束限制: 开启Range回源的前提是您的源站支持Range请求,即HTTP请求头中包含Range字段,否则可能导致回源失败 取值范围:
默认取值: 不涉及 |
ip_filter |
否 |
IpFilter object |
参数解释: IP黑白名单,对用户的请求IP地址进行过滤,从而限制访问来源 约束限制: 不涉及 |
referer |
否 |
RefererConfig object |
参数解释: referer黑白名单,对访问者身份进行识别和过滤,从而限制访问来源 约束限制: 不涉及 |
user_agent_filter |
否 |
UserAgentFilter object |
参数解释: UA黑白名单,对用户请求使用的代理过滤,从而限制访问来源 约束限制: 不涉及 |
flow_limit_strategy |
否 |
Array of FlowLimitStrategy objects |
参数解释: 设置用量封顶阈值,当实际用量大于阈值时停用域名,有效预防流量盗刷或恶意攻击带来的高额账单。
说明:
由于监控数据存在时延,域名将在用量达到阈值后的10分钟左右被停用
约束限制: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
是 |
String |
参数解释: 设置HTTP响应头参数 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
value |
否 |
String |
参数解释: 设置HTTP响应头参数的值 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
action |
是 |
String |
参数解释: 设置HTTP响应头操作类型 约束限制:
取值范围:
默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
match_type |
是 |
String |
参数解释: 匹配类型 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
match_value |
否 |
String |
参数解释: 缓存规则匹配内容 约束限制:
取值范围: 不涉及 默认取值: 不涉及 |
ttl |
否 |
Integer |
参数解释: 资源在CDN节点的缓存过期时间 约束限制: 最大支持365天 取值范围: 不涉及 默认取值: 0 |
ttl_unit |
是 |
String |
参数解释: 缓存过期时间单位 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
priority |
是 |
Integer |
参数解释: 缓存规则的优先级,数值越大,优先级越高 约束限制: 优先级不能相同 取值范围: 1-100 默认取值: 不涉及 |
follow_origin |
否 |
String |
参数解释: 缓存过期时间来源,设置CDN节点的缓存遵循源站还是CDN侧的配置 约束限制: 不涉及 取值范围:
默认取值: off: CDN节点的缓存过期时间遵循“缓存规则”中的“缓存过期时间” |
force_cache |
否 |
String |
参数解释: 强制缓存:CDN节点缓存过期时间是否忽略源站响应头Cache-Control中的no-cache、private、no-store字段 约束限制: 强制缓存与缓存过期时间来源功能配合使用,具体使用限制及配置效果请参考CDN用户指南的配置节点缓存规则章节 取值范围:
默认取值: off: 关闭强制缓存 |
url_parameter_type |
否 |
String |
参数解释: URL参数 约束限制: 不涉及 取值范围:
默认取值: full_url: 使用完整URL参数 |
url_parameter_value |
否 |
String |
参数解释: URL参数值 约束限制:
取值范围: 不涉及 默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
status |
是 |
String |
参数解释: 智能压缩开关 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
type |
否 |
String |
参数解释: 智能压缩类型 约束限制: 当配置了多种智能压缩类型时,优先使用brotli压缩 取值范围: 多种智能压缩类型用“,”分隔,可选值如下:
默认取值: 不涉及 |
file_type |
否 |
String |
参数解释: 需要压缩的文件类型 约束限制: 不涉及 取值范围:
默认取值: 开启状态下,首次传空时默认值为.js,.html,.css,.xml,.json,.shtml,.htm,否则为上次设置值 |
compress_min_length |
否 |
Integer |
参数解释: 压缩区间最小范围 约束限制: 如果未设置参与压缩的文件大小,默认大小为“0MB~30MB”的文件参与压缩。 取值范围:
默认取值: 不涉及 |
compress_max_length |
否 |
Integer |
参数解释: 压缩区间最大范围 约束限制: 如果未设置参与压缩的文件大小,默认大小为“0MB~30MB”的文件参与压缩。 取值范围:
默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
String |
参数解释: IP黑白名单类型 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
value |
否 |
String |
参数解释: 配置IP黑白名单
说明:
支持IPv6,支持配置IP地址和IP&掩码格式的网段
约束限制:
取值范围: 不涉及 默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
String |
参数解释: Referer黑白名单类型 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
value |
否 |
String |
参数解释: 域名或IP地址
说明:
域名、IP地址可以混合输入,支持泛域名和带端口的域名
约束限制:
取值范围: 不涉及 默认取值: 不涉及 |
include_empty |
否 |
Boolean |
参数解释: 是否包含空Referer
说明:
如果是黑名单并开启该选项,则表示无referer不允许访问
如果是白名单并开启该选项,则表示无referer允许访问 约束限制: 不涉及 取值范围:
默认取值: false: 不包含空 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
String |
参数解释: UA黑白名单类型 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
value |
否 |
String |
参数解释: UA黑白名单内容
说明:
此参数作为旧参数,将于近期下线,建议使用ua_list字段设置UA黑白名单内容
约束限制:
取值范围:
默认取值: 不涉及 |
include_empty |
否 |
Boolean |
参数解释: 是否包含空UA
说明:
如果黑名单并开启该选项,则表示无UA不允许访问
如果是白名单并开启该选项,则表示无UA允许访问 约束限制: 不涉及 取值范围: true: 包含空 false:不包含空 默认取值:
|
ua_list |
否 |
Array of strings |
参数解释: 配置UA黑白名单 约束限制:
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
strategy_type |
否 |
String |
参数解释: 用量统计类型 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
item_type |
否 |
String |
参数解释: 用量封顶类型 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
limit_value |
否 |
String |
参数解释: 用量封顶阈值,域名用量达到该阈值后,将会停用域名 约束限制: 不涉及 取值范围: 必须为正整数 默认取值: 不涉及 |
alarm_percent_threshold |
否 |
String |
参数解释: 用量告警阈值,域名用量达到该阈值后,将会发送告警 约束限制: 不涉及 取值范围: 1-90 默认取值: 不涉及 |
ban_time |
否 |
String |
参数解释: 域名封禁周期 约束限制: ban_time设置为0时,表示不自动解封,需要客户手动解封域名 取值范围:
默认取值: 不涉及 |
请求示例
POST https://cdn.myhuaweicloud.com/v1.0/cdn/configuration/templates { "tml_name" : "example", "remark" : "example remark", "configs" : { "http_response_header" : [ { "action" : "set", "name" : "Content-Disposition", "value" : "example" } ] } }
响应示例
无
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 |
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 CreateDomainTemplateSolution { 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(); CreateDomainTemplateRequest request = new CreateDomainTemplateRequest(); CreateTemplateRequestBody body = new CreateTemplateRequestBody(); List listConfigsHttpResponseHeader = new ArrayList<>(); listConfigsHttpResponseHeader.add( new HttpResponseHeader() .withName("Content-Disposition") .withValue("example") .withAction("set") ); TemplateConfigs configsbody = new TemplateConfigs(); configsbody.withHttpResponseHeader(listConfigsHttpResponseHeader); body.withConfigs(configsbody); body.withRemark("example remark"); body.withTmlName("example"); request.withBody(body); try { CreateDomainTemplateResponse response = client.createDomainTemplate(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 |
# coding: utf-8 import os 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 = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] credentials = GlobalCredentials(ak, sk) client = CdnClient.new_builder() \ .with_credentials(credentials) \ .with_region(CdnRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateDomainTemplateRequest() listHttpResponseHeaderConfigs = [ HttpResponseHeader( name="Content-Disposition", value="example", action="set" ) ] configsbody = TemplateConfigs( http_response_header=listHttpResponseHeaderConfigs ) request.body = CreateTemplateRequestBody( configs=configsbody, remark="example remark", tml_name="example" ) response = client.create_domain_template(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 |
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.CreateDomainTemplateRequest{} valueHttpResponseHeader:= "example" var listHttpResponseHeaderConfigs = []model.HttpResponseHeader{ { Name: "Content-Disposition", Value: &valueHttpResponseHeader, Action: "set", }, } configsbody := &model.TemplateConfigs{ HttpResponseHeader: &listHttpResponseHeaderConfigs, } remarkCreateTemplateRequestBody:= "example remark" request.Body = &model.CreateTemplateRequestBody{ Configs: configsbody, Remark: &remarkCreateTemplateRequestBody, TmlName: "example", } response, err := client.CreateDomainTemplate(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
204 |
成功响应 |
default |
异常响应 |
错误码
请参见错误码。