You need to enable JavaScript to run this app.
导航

CreateRules

最近更新时间2024.02.29 14:48:19

首次发布时间2022.05.20 22:34:38

API 说明

API 名称:CreateRules。
API 域名:open.volcengineapi.com 。
API 描述:为监听器添加转发规则,将来自不同域名、URL的访问请求转发到不同的服务器组。

使用限制

节流限制:每秒最多提交 5 个 API 请求。

快速调试

URI 参数

在使用该部分 API 提交请求时必须包含以下 URI 参数。

除了 URI 参数,该 API 请求还需要包含签名参数。关于更多签名参数的信息,参见公共请求参数

名称类型是否必选格式说明
Action
string
[a-zA-Z]+
API 名称,如 CreateRules。
VersionstringYYYY-MM-DDAPI 版本信息。该参数的取值是 2020-04-01 。
X-Expiresint900表示签名的有效时间,单位是秒,默认值是900。

请求正文

在使用该 API 提交请求时,请求正文中可以包含的参数如下。

参数类型是否必选参数说明示例值
ListenerId
String
监听器ID。
lsn-2fea4ayvu2g3k5oxruuz****
RulesArray配置转发规则相关信息。详见 Rules-

Rules

参数类型是否必选参数说明示例值
Rules.N.Domain

List of Struct

转发规则的域名,支持泛域名和精确域名。具体规范如下:

  • 需至少包含一个‘.’,且不允许以‘.’开头或结尾。
  • 仅允许包含字母、数字、‘.’、‘-‘、‘*’。
  • 长度限制为1 ~ 128个字符。
  • 泛域名:使用“*”代替1个或多个字符。
    • “*”必须在域名开头或结尾。
    • 同一条域名中“*”不能出现两次。
    • “*”前后不能有除了.以外的字符。
    • 合法示例:*.com、www.test.*。
    • 非法示例:*aaa.com、www.*.com。
  • 精确域名:符合域名规范的精确域名,例如:www.test.com。
  • - N:表示域名的序号,取值范围 1~20。
  • 多个域名间使用“&”分隔。
  • Rules.N.Domain 和 Rules.N.Url两者至少需指定一个,且 Rules.N.Domain 和 Rules.N.Url的组合在同一个监听器内必须唯一。
Rules.1.Domain=*.com&Rules.2.Domain=www.test.com
Rules.N.Url

List of Struct

转发规则的URL,仅支持绝对路径。具体规范如下:

  • 必须以正斜线“/”开头。
  • 仅允许包含字母、数字、‘-’、‘_’、‘/’、‘.’、‘%’、‘?’、‘#’、‘&’、‘=’等字符。
  • 长度限制为1 ~ 128个字符。
  • 若指定Domain,则Url不传入数值时,默认为“/”。
  • - N:表示转发规则的序号,取值范围为1 ~ 20。
  • 多个转发规则间使用“&”分隔。
  • Rules.N.Domain和Rules.N.Url两者至少需指定一个,且Rules.N.Domain和 Rules.N.Url的组合在同一个监听器内必须唯一。
  • 当Rules.N.Domain设置为空时,Rules.N.Url不允许只为正斜线“/”。
Rules.1.Url=/&Rules.2.Url=/poo
Rules.N.RuleAction

List of Struct

转发规则动作,目前支持:

  • 为空:默认转发至服务器组。
  • Redirect:重定向。
Rules.1.RuleAction=''&Rules.2.RuleAction=Redirect
Rules.N.ServerGroupId

List of Struct

转发到后端服务器组的ID。

  • - N:表示转发规则的序号,取值范围为1 ~ 20。
  • 当转发规则动作为空,即转发至服务器组,该参数为必填项。
  • 多个转发规则间使用“&”分隔。
Rules.1.ServerGroupId=rsp-bp1o94dp5i6ea****&Rules.2.ServerGroupId=rsp-2fea4bshkqv4****
Rules.N.Description

List of Struct

转发规则的描述,默认值为空字符。具体规范如下:

  • - N:表示转发规则的序号,取值范围为1 ~ 20。
  • 多个转发规则间使用“&”分隔。
  • 必须以字母或中文开头,可包含数字、英文逗号(,)、点号(.)、下划线(_)、空格( )、等号(=)、短横线(-)、中文逗号(,)、中文句号(。)。
  • 长度限制为1 ~ 255个字符。

-

Rules.N.TrafficLimitEnabled

String

转发规则 QPS 限速开关:

  • on:开启。

  • off:关闭(默认)。

on

Rules.N.TrafficLimitQPS

Integer

当 Rules.N.TrafficLimitEnabled 为 on 时,本字段必选。每秒请求数。取值范围:100~150000。

100

Rules.N.RewriteEnabled

String

转发规则重写配置的开关,仅当RuleAction 为空(即,转发至服务器组)时,允许配置该参数且生效。仅支持白名单用户使用,如需体验,请提交申请。支持取值如下:

  • on:开启。

  • off:关闭。

on

Rules.N.RedirectConfig
Struct转发规则重定向配置,具体可参见下表 RedirectConfig-
Rules.N.RewriteConfigArray转发规则重写配置,具体可参见 RewriteConfig-

RedirectConfig

参数类型是否必选参数说明示例值

Rules.N.RedirectConfig.RedirectDomain

List of Struct

  • 重定向域名,仅支持精确域名。

    • 参数 N:表示域名的序号,取值范围 1~20。

    • 多个域名间使用“&”分隔。

    • 具体规范如下:

      • 需至少包含一个‘.’,且不允许以‘.’开头或结尾。

      • 仅允许包含字母、数字、‘.’、‘-‘。

      • 长度限制为1 ~ 128个字符。

      • 精确域名:符合域名规范的精确域名,例如:www.test.com。

  • 当转发规则动作为 Redirect,即重定向时,若该参数不指定,会被赋值为默认值(空),最终效果为与请求域名保持一致。

Rules.1.RedirectConfig.RedirectDomain=*.com&Rules.2.RedirectConfig.RedirectDomain=www.test.com

Rules.N.RedirectConfig.RedirectUri

List of Struct

  • 重定向 URI。

    • 参数 N:表示域名的序号,取值范围 1~20。
      • 多个域名间使用“&”分隔。
  • 具体规范如下:

    • 必须以正斜线“/”开头。

    • 仅允许包含字母、数字、‘-’、‘_’、‘/’、‘.’、‘%’、‘?’、‘#’、‘&’、‘=’等字符。

    • 长度限制为1 ~ 128个字符。

  • 当转发规则动作为 Redirect,即重定向时,若该参数不指定,会被赋值为默认值(空),最终效果为与请求URI保持一致。

Rules.1.RedirectConfig.RedirectUri=/&Rules.2.RedirectConfig.RedirectUri=/poo

Rules.N.RedirectConfig.RedirectPort

List of Struct

  • 重定向端口,取值:1 - 65535。

    • 参数 N:表示域名的序号,取值范围 1~20。

    • 多个域名间使用“&”分隔。

  • 当转发规则动作为Redirect,即重定向时,若该参数不指定,否则将赋值为默认值(空),最终效果为与请求端口保持一致。

Rules.1.RedirectConfig.RedirectPort=80&Rules.2.RedirectConfig.RedirectPort=443

Rules.N.RedirectConfig.RedirectHttpCode

List of Struct

  • 重定向状态码,支持301(默认),302,307,308。

    • 参数 N:表示域名的序号,取值范围 1~20。

    • 多个域名间使用“&”分隔。

  • 当转发规则动作为Redirect,即重定向时,若该参数不指定,则默认赋值301。

Rules.1.RedirectConfig.RedirectHttpCode=301&Rules.2.RedirectConfig.RedirectHttpCode=302

Rules.N.RedirectConfig.RedirectProtocol

List of Struct

  • 重定向使用的协议,支持HTTP,HTTPS(默认)。

    • 参数 N:表示域名的序号,取值范围 1~20。

    • 多个域名间使用“&”分隔。

  • 当转发规则动作为Redirect,即重定向时,若该参数不指定,则默认赋值为 HTTPS 。

Rules.1.RedirectConfig.RedirectProtocol=HTTP&Rules.2.RedirectConfig.RedirectProtocol=HTTPS

RewriteConfig

参数类型是否必选参数说明示例值

Rules.N.RewriteConfig.RewritePath

String

  • 重写路径。

    • 参数 N:表示域名的序号,取值范围 1~20。
      • 多个域名间使用“&”分隔。
  • 具体规范如下:

    • 必须以正斜线“/”开头。

    • 仅允许包含字母、数字、‘-’、‘_’、‘/’、‘.’、‘%’、‘?’、‘#’、‘&’等字符。

    • 长度限制为1 ~ 128个字符。

    • 支持正则表达式替换,重写路径中需要包含${1}${2}${3}中的一个或多个,且这三个变量不支持使用其余字符代替。

Rules.1.RewriteConfig.RewritePath=/{1}/${2}&Rules.2.RewriteConfig.RewritePath=/poo

响应正文

参数类型参数说明示例值
RequestId
String
请求ID。
20210811152539010225146063030****
RuleIdsList转发规则ID。["rule-****","rule- ****"]

示例

请求示例

GET /?Action=CreateRules&ListenerId=lsn-1g0puwcxuf****ibuxxw2pmf7&Rules.1.Domain=test.com&Rules.1.ServerGroupId=rsp-3ciynvqsspiww****rsz73tzn&Rules.1.Url=/test&Version=2020-04-01 HTTP/1.1
Host: open.volcengineapi.com
Region: cn-beijing
ServiceName: alb

响应示例

{
    "ResponseMetadata": {
        "RequestId": "202108131613570****5146063000AD724",
        "Action": "CreateRules",
        "Version": "2020-04-01",
        "Service": "alb",
        "Region": "cn-beijing"
    },
    "Result": {
        "RequestId": "2021081316135****225146063000AD724",
        "RuleIds": [
            "rule-3ciynwk****b46c6rrt4jszkd"
        ]
    }
}

错误码

如果响应正文包含 Error 字段,则表示 API 请求失败。此处仅展示当前 API 的错误码,更多错误码请参见公共错误码

HTTP Code

错误码

错误信息

错误描述

400InvalidIndexOrder.MalformedThe specified index order is malformed.指定的索引顺序参数格式不合法。

400

OperationDenied.AccountArrears

The request on the specified resource is denied due to the account being in arrears status.

因账号处于欠费状态,对于该资源的操作请求被拒绝。

400

MissingParameter

The request is missing a required parameter. Ensure that you have supplied all the required parameters for the request; for example, 'Rules'.

该请求缺少必要参数。请确保发起请求已提供全部必要参数,比如: Rules。

400

LimitExceed.Rule

You've reached the limit on the number of rules that you can operate at a time.

已达到单次可操作的转发规则的数量上限。

400InvalidRules.TrafficLimitEnabled.MalformedThe specified Rules.TrafficLimitEnabled is malformed.指定的 Rules.TrafficLimitEnabled 参数格式不合法。
400InvalidRules.TrafficLimitQPS.MalformedThe specified Rules.TrafficLimitQPS is malformed.指定的 Rules.TrafficLimitQPS 参数格式不合法。

400

MissingParameter

The request is missing a required parameter. Ensure that you have supplied all the required parameters for the request; for example, 'Rules.Domain, Rules.Url'.

该请求缺少必要参数。请确保发起请求已提供全部必要参数,比如: Rules.Domain, Rules.Url。

400

OperationDenied.DefaultRule

The request on the specified rule is denied due to the default rule can not be added.

因默认转发规则不支持人为添加,对于该转发规则的操作请求被拒绝。

400InvalidRules.Domain.MalformedThe specified Rules.Domain is malformed.指定的 Rules.Domain 参数格式不合法。
400InvalidRules.Url.MalformedThe specified Rules.Url is malformed.指定的 Rules.Url 参数格式不合法。
400InvalidRules.Url.DuplicatedThe specified Rules.Url is duplicated.指定的 Rules.Url 重复。
400InvalidRules.Description.MalformedThe specified Rules.Description is malformed.指定的 Rules.Description 参数格式不合法。

400

MissingParameter

The request is missing a required parameter. Ensure that you have supplied all the required parameters for the request; for example, 'Rules.ServerGroupId'.

该请求缺少必要参数。请确保发起请求已提供全部必要参数,比如: Rules.ServerGroupId。

400

InvalidVpcForServerGroup.LoadBalancerMismatch

The specified VPC of ServerGroup and LoadBalancer do not match.

指定的服务器组和 ALB 实例的 VPC 不匹配。

400InvalidServerGroup.InvalidStatusThe specified ServerGroup is not in the correct status for the request.指定的服务器组所处状态无法响应该请求。

400
400

OperationDenied.RewriteEnabledInRedirectAction
InvalidRules.RedirectConfig.Malformed

The request on the specified Rule is denied due to the rewrite config is not allowed to be configured in redirect action.
The specified Rules.RedirectConfig is malformed.

因重定向转发动作不支持重写功能,对于该转发规则的操作请求被拒绝。
指定的 Rules.RedirectConfig 参数格式不合法。重定向协议与监听器协议一致,域名、端口、URI 至少填写一项。

400InvalidRules.RedirectConfig.RedirectHttpCode.MalformedThe specified Rules.RedirectConfig.RedirectHttpCode is malformed.指定的 Rules.RedirectConfig.RedirectHttpCode 参数格式不合法。
400InvalidRules.RedirectConfig.RedirectProtocol.MalformedThe specified Rules.RedirectConfig.RedirectProtocol is malformed.指定的 Rules.RedirectConfig.RedirectProtocol 参数格式不合法。
400InvalidRules.RedirectConfig.RedirectDomain.MalformedThe specified Rules.RedirectConfig.RedirectDomain is malformed.指定的 Rules.RedirectConfig.RedirectDomain 参数格式不合法。
400InvalidRules.RedirectConfig.RedirectUri.MalformedThe specified Rules.RedirectConfig.RedirectUri is malformed.指定的 Rules.RedirectConfig.RedirectUri 参数格式不合法。
400InvalidRules.RedirectConfig.RedirectPort.MalformedThe specified Rules.RedirectConfig.RedirectPort is malformed.指定的 Rules.RedirectConfig.RedirectPort 参数格式不合法。

400

InvalidRules.RuleAction.Malformed

The specified Rules.RuleAction is malformed.

指定的 Rules.RuleAction 参数格式不合法。

400

InvalidRules.RewriteEnabled.Malformed

The specified Rules.RewriteEnabled is malformed.

指定的 Rules.RewriteEnabled 参数格式不合法。

400InvalidRules.RewriteConfig.RewritePath.MalformedThe specified Rules.RewriteConfig.RewritePath is malformed.指定的 Rules.RewriteConfig.RewritePath 参数格式不合法。

400

QuotaExceed.RulePerInstance

You've reached the limit on the number of rules per ALB you can create in, resource xxx, usage xx/xx.

已达到每个实例可创建转发规则的数量上限。资源是xxx,目前已使用xxx,配额为xxx。

400

QuotaExceed.ServerPerInstance

You've reached the limit on the number of backend servers per ALB you can associate with, resource xxx, usage xx/xx.

已达到每个实例可关联的后端服务器的数量上限。资源是xxx,目前已使用xxx,配额为xxx。

400QuotaExceed.RulePerGroupYou've reached the limit on the number of rules per server group you can associate with, resource xxx, usage xx/xx.已达到每个服务器组可关联转发规则的数量上限。资源是xxx,目前已使用xxx,配额为xxx。

400

InvalidLoadBalancer.InvalidStatus

The related LoadBalancer is not in the correct status for the request.

关联的 ALB 实例所处状态无法响应该请求。

400

InvalidServerGroup.InvalidStatus

The specified ServerGroup is not in the correct status for the request.

指定的服务器组所处状态无法响应该请求。

403

Forbidden

You are not authorized to configure traffic limit for rule.

您无权限对指定转发规则配置限速值。

403

Forbidden

You are not authorized to create rule with regex url.

您无权限创建正则表达式 url 的转发规则。

403ForbiddenYou are not authorized to configure rewrite for rule.您无权限对指定转发规则配置重写。
404InvalidListener.NotFoundThe specified Listener does not exist.指定的监听器不存在。

404

InvalidServerGroup.NotFound

The specified ServerGroup does not exist.

指定的服务器组不存在。

409InvalidRules.ConflictThe specified Rule already exists.指定的转发规则已存在。