itecdn 5.x用户文档
itecdn 5.x / 用户 API

创建四层转发

POST/v1/streams

创建一个或多个四层转发。请求体可以是单个对象或对象数组;每项均必须指定用户套餐、监听配置、回源端口和源站列表。未指定的协议、负载方式和 PROXY protocol 使用当前区域及用户默认配置。管理员可额外指定用户、区域、线路和 CNAME 资源。

身份认证

access-token

api-key + api-secret

认证定义
{
  "AccessToken": {
    "type": "apiKey",
    "in": "header",
    "name": "access-token",
    "description": "通过登录接口获得的短期访问令牌。"
  },
  "ApiKey": {
    "type": "apiKey",
    "in": "header",
    "name": "api-key",
    "description": "API Key;必须和 api-secret 同时发送。"
  },
  "ApiSecret": {
    "type": "apiKey",
    "in": "header",
    "name": "api-secret",
    "description": "API Secret;必须和 api-key 同时发送。"
  }
}

请求参数

未定义路径、查询或请求头参数。

请求体 · 必填

application/json

oneOf

oneOf · 1 · object
字段类型必填说明与约束
user_packageinteger必填

必填。用户套餐 ID;套餐须存在、可用且属于当前用户。

约束 / 默认值 / 示例
{
  "minimum": 1
}
listenarray <object>必填

必填。监听列表;端口必须在所在区域允许范围内且未占用。

约束 / 默认值 / 示例
{
  "minItems": 1
}
展开字段结构

必填。监听列表;端口必须在所在区域允许范围内且未占用。

数组元素 · object
字段类型必填说明与约束
portinteger必填

必填。监听端口。

约束 / 默认值 / 示例
{
  "minimum": 1,
  "maximum": 65535
}
protocolstring可选

监听协议;创建时省略则使用默认协议。

约束 / 默认值 / 示例
{
  "enum": [
    "tcp",
    "udp"
  ]
}
backend_portinteger必填

必填。源站回源端口。

约束 / 默认值 / 示例
{
  "minimum": 1,
  "maximum": 65535
}
backendarray <object>必填

必填。源站列表,至少有一个状态为 up 的源站。

约束 / 默认值 / 示例
{
  "minItems": 1
}
展开字段结构

必填。源站列表,至少有一个状态为 up 的源站。

数组元素 · object
字段类型必填说明与约束
addrstring必填

必填。源站 IPv4、IPv6 或域名,不能是系统节点 IP。

weightinteger可选

源站权重;创建时省略为 1。

约束 / 默认值 / 示例
{
  "minimum": 1,
  "maximum": 10
}
statestring可选

源站状态;创建时省略为 up。ip_hash 不支持备用源站。

约束 / 默认值 / 示例
{
  "enum": [
    "up",
    "down",
    "backup"
  ]
}
balance_waystring可选

负载均衡方式;省略时使用默认配置。

约束 / 默认值 / 示例
{
  "enum": [
    "ip_hash",
    "rr"
  ]
}
proxy_protocolinteger可选

是否向源站发送 PROXY protocol;省略时使用默认配置。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
conn_limitinteger可选

连接数限制;可为空。

约束 / 默认值 / 示例
{
  "minimum": 0
}
aclobject可选

访问控制配置。

约束 / 默认值 / 示例
{
  "additionalProperties": false
}
展开字段结构

访问控制配置。

字段类型必填说明与约束
enableinteger可选

是否启用 ACL。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
block_regionstring可选

地域拦截配置。

desstring可选

转发备注;会进行 XSS 过滤,可为空。

enableinteger可选

是否启用转发。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
statestring可选

管理员专用。四层转发业务状态:200 正常、512 套餐到期、513 流量超限、514 锁定;创建时省略则为 200。

约束 / 默认值 / 示例
{
  "enum": [
    "200",
    "512",
    "513",
    "514"
  ],
  "default": "200"
}
groupsstring可选

应用用户默认配置和关联转发组的 ID 列表,使用英文逗号分隔。

uidinteger可选

管理员专用。指定归属用户 ID。

cname_domaininteger可选

管理员专用。CNAME 域名配置 ID。

cname_modestring可选

管理员专用。CNAME 使用方式。

约束 / 默认值 / 示例
{
  "enum": [
    "package",
    "site"
  ]
}
cname_hostnamestring可选

管理员专用。CNAME 主机名。

region_idinteger可选

管理员专用。区域 ID。

node_group_idinteger可选

管理员专用。主线路组 ID。

backup_node_groupinteger可选

管理员专用。备用线路组 ID。

约束 / 默认值 / 示例
{
  "nullable": true
}
enable_ipv6integer可选

是否启用 IPv6。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
oneOf · 2 · array <object>

批量创建;每一项字段与单对象创建相同。

数组元素 · object
字段类型必填说明与约束
user_packageinteger必填

必填。用户套餐 ID;套餐须存在、可用且属于当前用户。

约束 / 默认值 / 示例
{
  "minimum": 1
}
listenarray <object>必填

必填。监听列表;端口必须在所在区域允许范围内且未占用。

约束 / 默认值 / 示例
{
  "minItems": 1
}
展开字段结构

必填。监听列表;端口必须在所在区域允许范围内且未占用。

数组元素 · object
字段类型必填说明与约束
portinteger必填

必填。监听端口。

约束 / 默认值 / 示例
{
  "minimum": 1,
  "maximum": 65535
}
protocolstring可选

监听协议;创建时省略则使用默认协议。

约束 / 默认值 / 示例
{
  "enum": [
    "tcp",
    "udp"
  ]
}
backend_portinteger必填

必填。源站回源端口。

约束 / 默认值 / 示例
{
  "minimum": 1,
  "maximum": 65535
}
backendarray <object>必填

必填。源站列表,至少有一个状态为 up 的源站。

约束 / 默认值 / 示例
{
  "minItems": 1
}
展开字段结构

必填。源站列表,至少有一个状态为 up 的源站。

数组元素 · object
字段类型必填说明与约束
addrstring必填

必填。源站 IPv4、IPv6 或域名,不能是系统节点 IP。

weightinteger可选

源站权重;创建时省略为 1。

约束 / 默认值 / 示例
{
  "minimum": 1,
  "maximum": 10
}
statestring可选

源站状态;创建时省略为 up。ip_hash 不支持备用源站。

约束 / 默认值 / 示例
{
  "enum": [
    "up",
    "down",
    "backup"
  ]
}
balance_waystring可选

负载均衡方式;省略时使用默认配置。

约束 / 默认值 / 示例
{
  "enum": [
    "ip_hash",
    "rr"
  ]
}
proxy_protocolinteger可选

是否向源站发送 PROXY protocol;省略时使用默认配置。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
conn_limitinteger可选

连接数限制;可为空。

约束 / 默认值 / 示例
{
  "minimum": 0
}
aclobject可选

访问控制配置。

约束 / 默认值 / 示例
{
  "additionalProperties": false
}
展开字段结构

访问控制配置。

字段类型必填说明与约束
enableinteger可选

是否启用 ACL。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
block_regionstring可选

地域拦截配置。

desstring可选

转发备注;会进行 XSS 过滤,可为空。

enableinteger可选

是否启用转发。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
statestring可选

管理员专用。四层转发业务状态:200 正常、512 套餐到期、513 流量超限、514 锁定;创建时省略则为 200。

约束 / 默认值 / 示例
{
  "enum": [
    "200",
    "512",
    "513",
    "514"
  ],
  "default": "200"
}
groupsstring可选

应用用户默认配置和关联转发组的 ID 列表,使用英文逗号分隔。

uidinteger可选

管理员专用。指定归属用户 ID。

cname_domaininteger可选

管理员专用。CNAME 域名配置 ID。

cname_modestring可选

管理员专用。CNAME 使用方式。

约束 / 默认值 / 示例
{
  "enum": [
    "package",
    "site"
  ]
}
cname_hostnamestring可选

管理员专用。CNAME 主机名。

region_idinteger可选

管理员专用。区域 ID。

node_group_idinteger可选

管理员专用。主线路组 ID。

backup_node_groupinteger可选

管理员专用。备用线路组 ID。

约束 / 默认值 / 示例
{
  "nullable": true
}
enable_ipv6integer可选

是否启用 IPv6。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
完整 Schema
{
  "oneOf": [
    {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "user_package",
        "listen",
        "backend_port",
        "backend"
      ],
      "properties": {
        "user_package": {
          "type": "integer",
          "minimum": 1,
          "description": "必填。用户套餐 ID;套餐须存在、可用且属于当前用户。"
        },
        "listen": {
          "type": "array",
          "minItems": 1,
          "description": "必填。监听列表;端口必须在所在区域允许范围内且未占用。",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "port"
            ],
            "properties": {
              "port": {
                "type": "integer",
                "minimum": 1,
                "maximum": 65535,
                "description": "必填。监听端口。"
              },
              "protocol": {
                "type": "string",
                "enum": [
                  "tcp",
                  "udp"
                ],
                "description": "监听协议;创建时省略则使用默认协议。"
              }
            }
          }
        },
        "backend_port": {
          "type": "integer",
          "minimum": 1,
          "maximum": 65535,
          "description": "必填。源站回源端口。"
        },
        "backend": {
          "type": "array",
          "minItems": 1,
          "description": "必填。源站列表,至少有一个状态为 `up` 的源站。",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "addr"
            ],
            "properties": {
              "addr": {
                "type": "string",
                "description": "必填。源站 IPv4、IPv6 或域名,不能是系统节点 IP。"
              },
              "weight": {
                "type": "integer",
                "minimum": 1,
                "maximum": 10,
                "description": "源站权重;创建时省略为 1。"
              },
              "state": {
                "type": "string",
                "enum": [
                  "up",
                  "down",
                  "backup"
                ],
                "description": "源站状态;创建时省略为 `up`。`ip_hash` 不支持备用源站。"
              }
            }
          }
        },
        "balance_way": {
          "type": "string",
          "enum": [
            "ip_hash",
            "rr"
          ],
          "description": "负载均衡方式;省略时使用默认配置。"
        },
        "proxy_protocol": {
          "type": "integer",
          "enum": [
            0,
            1
          ],
          "description": "是否向源站发送 PROXY protocol;省略时使用默认配置。"
        },
        "conn_limit": {
          "type": "integer",
          "minimum": 0,
          "description": "连接数限制;可为空。"
        },
        "acl": {
          "type": "object",
          "description": "访问控制配置。",
          "additionalProperties": false,
          "properties": {
            "enable": {
              "type": "integer",
              "enum": [
                0,
                1
              ],
              "description": "是否启用 ACL。"
            }
          }
        },
        "block_region": {
          "type": "string",
          "description": "地域拦截配置。"
        },
        "des": {
          "type": "string",
          "description": "转发备注;会进行 XSS 过滤,可为空。"
        },
        "enable": {
          "type": "integer",
          "enum": [
            0,
            1
          ],
          "description": "是否启用转发。"
        },
        "state": {
          "type": "string",
          "enum": [
            "200",
            "512",
            "513",
            "514"
          ],
          "description": "管理员专用。四层转发业务状态:200 正常、512 套餐到期、513 流量超限、514 锁定;创建时省略则为 200。",
          "default": "200"
        },
        "groups": {
          "type": "string",
          "description": "应用用户默认配置和关联转发组的 ID 列表,使用英文逗号分隔。"
        },
        "uid": {
          "type": "integer",
          "description": "管理员专用。指定归属用户 ID。"
        },
        "cname_domain": {
          "type": "integer",
          "description": "管理员专用。CNAME 域名配置 ID。"
        },
        "cname_mode": {
          "type": "string",
          "enum": [
            "package",
            "site"
          ],
          "description": "管理员专用。CNAME 使用方式。"
        },
        "cname_hostname": {
          "type": "string",
          "description": "管理员专用。CNAME 主机名。"
        },
        "region_id": {
          "type": "integer",
          "description": "管理员专用。区域 ID。"
        },
        "node_group_id": {
          "type": "integer",
          "description": "管理员专用。主线路组 ID。"
        },
        "backup_node_group": {
          "type": "integer",
          "nullable": true,
          "description": "管理员专用。备用线路组 ID。"
        },
        "enable_ipv6": {
          "type": "integer",
          "enum": [
            0,
            1
          ],
          "description": "是否启用 IPv6。"
        }
      }
    },
    {
      "type": "array",
      "minItems": 1,
      "description": "批量创建;每一项字段与单对象创建相同。",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "user_package",
          "listen",
          "backend_port",
          "backend"
        ],
        "properties": {
          "user_package": {
            "type": "integer",
            "minimum": 1,
            "description": "必填。用户套餐 ID;套餐须存在、可用且属于当前用户。"
          },
          "listen": {
            "type": "array",
            "minItems": 1,
            "description": "必填。监听列表;端口必须在所在区域允许范围内且未占用。",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "port"
              ],
              "properties": {
                "port": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 65535,
                  "description": "必填。监听端口。"
                },
                "protocol": {
                  "type": "string",
                  "enum": [
                    "tcp",
                    "udp"
                  ],
                  "description": "监听协议;创建时省略则使用默认协议。"
                }
              }
            }
          },
          "backend_port": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535,
            "description": "必填。源站回源端口。"
          },
          "backend": {
            "type": "array",
            "minItems": 1,
            "description": "必填。源站列表,至少有一个状态为 `up` 的源站。",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "addr"
              ],
              "properties": {
                "addr": {
                  "type": "string",
                  "description": "必填。源站 IPv4、IPv6 或域名,不能是系统节点 IP。"
                },
                "weight": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 10,
                  "description": "源站权重;创建时省略为 1。"
                },
                "state": {
                  "type": "string",
                  "enum": [
                    "up",
                    "down",
                    "backup"
                  ],
                  "description": "源站状态;创建时省略为 `up`。`ip_hash` 不支持备用源站。"
                }
              }
            }
          },
          "balance_way": {
            "type": "string",
            "enum": [
              "ip_hash",
              "rr"
            ],
            "description": "负载均衡方式;省略时使用默认配置。"
          },
          "proxy_protocol": {
            "type": "integer",
            "enum": [
              0,
              1
            ],
            "description": "是否向源站发送 PROXY protocol;省略时使用默认配置。"
          },
          "conn_limit": {
            "type": "integer",
            "minimum": 0,
            "description": "连接数限制;可为空。"
          },
          "acl": {
            "type": "object",
            "description": "访问控制配置。",
            "additionalProperties": false,
            "properties": {
              "enable": {
                "type": "integer",
                "enum": [
                  0,
                  1
                ],
                "description": "是否启用 ACL。"
              }
            }
          },
          "block_region": {
            "type": "string",
            "description": "地域拦截配置。"
          },
          "des": {
            "type": "string",
            "description": "转发备注;会进行 XSS 过滤,可为空。"
          },
          "enable": {
            "type": "integer",
            "enum": [
              0,
              1
            ],
            "description": "是否启用转发。"
          },
          "state": {
            "type": "string",
            "enum": [
              "200",
              "512",
              "513",
              "514"
            ],
            "description": "管理员专用。四层转发业务状态:200 正常、512 套餐到期、513 流量超限、514 锁定;创建时省略则为 200。",
            "default": "200"
          },
          "groups": {
            "type": "string",
            "description": "应用用户默认配置和关联转发组的 ID 列表,使用英文逗号分隔。"
          },
          "uid": {
            "type": "integer",
            "description": "管理员专用。指定归属用户 ID。"
          },
          "cname_domain": {
            "type": "integer",
            "description": "管理员专用。CNAME 域名配置 ID。"
          },
          "cname_mode": {
            "type": "string",
            "enum": [
              "package",
              "site"
            ],
            "description": "管理员专用。CNAME 使用方式。"
          },
          "cname_hostname": {
            "type": "string",
            "description": "管理员专用。CNAME 主机名。"
          },
          "region_id": {
            "type": "integer",
            "description": "管理员专用。区域 ID。"
          },
          "node_group_id": {
            "type": "integer",
            "description": "管理员专用。主线路组 ID。"
          },
          "backup_node_group": {
            "type": "integer",
            "nullable": true,
            "description": "管理员专用。备用线路组 ID。"
          },
          "enable_ipv6": {
            "type": "integer",
            "enum": [
              0,
              1
            ],
            "description": "是否启用 IPv6。"
          }
        }
      }
    }
  ],
  "example": {
    "user_package": 8,
    "listen": [
      {
        "port": 443,
        "protocol": "tcp"
      }
    ],
    "backend_port": 443,
    "backend": [
      {
        "addr": "198.51.100.10",
        "weight": 1,
        "state": "up"
      }
    ]
  }
}

请求体示例

{
  "user_package": 8,
  "listen": [
    {
      "port": 443,
      "protocol": "tcp"
    }
  ],
  "backend_port": 443,
  "backend": [
    {
      "addr": "198.51.100.10",
      "weight": 1,
      "state": "up"
    }
  ]
}

响应

HTTP 200

请求已被处理。成功时 code 为 0、msg 为“四层转发添加成功”、data 为新建转发 ID 的逗号分隔字符串;业务校验失败仍返回 HTTP 200。

application/json

object

字段类型必填说明与约束
codeinteger必填

业务状态码;成功为 0。

约束 / 默认值 / 示例
{
  "example": 0
}
msgstring必填

处理结果说明。

约束 / 默认值 / 示例
{
  "example": "四层转发添加成功"
}
datastring必填

成功时的新建转发 ID,多个 ID 用英文逗号分隔;失败时为空字符串。

约束 / 默认值 / 示例
{
  "example": "101,102"
}
完整 Schema
{
  "type": "object",
  "required": [
    "code",
    "msg",
    "data"
  ],
  "properties": {
    "code": {
      "type": "integer",
      "description": "业务状态码;成功为 0。",
      "example": 0
    },
    "msg": {
      "type": "string",
      "description": "处理结果说明。",
      "example": "四层转发添加成功"
    },
    "data": {
      "type": "string",
      "description": "成功时的新建转发 ID,多个 ID 用英文逗号分隔;失败时为空字符串。",
      "example": "101,102"
    }
  }
}

示例

{
  "code": 0,
  "msg": "四层转发添加成功",
  "data": "101"
}

创建成功

{
  "code": 0,
  "msg": "四层转发添加成功",
  "data": "101"
}

缺少监听

{
  "code": "stream-26",
  "msg": "listen不能为空",
  "data": ""
}

cURL 示例

根据文档生成;请替换主控地址、路径参数和凭证,并按上表补充查询参数。

curl --request POST \
  "https://master.example.invalid/v1/streams" \
  --header "access-token: YOUR_ACCESS_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"user_package": 8, "listen": [{"port": 443, "protocol": "tcp"}], "backend_port": 443, "backend": [{"addr": "198.51.100.10", "weight": 1, "state": "up"}]}'

查看完整接口 JSON