创建HTTP监听器
更新时间:2026-07-16
描述
- 在指定LoadBalancer下,创建一个基于HTTP协议的监听器,监听一个前端端口,将发往该端口的所有HTTP请求,转发到后端服务器监听的后端端口上
OpenAPI Explorer
去调试
您可以在 OpenAPI Explorer 中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer 可以自动生成 SDK 代码示例。
请求结构
Text
1POST /v{version}/blb/{blbId}/HTTPlistener?clientToken={clientToken} HTTP/1.1
2Host: blb.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "listenerPort":listenerPort,
7 "backendPort":backendPort,
8 "scheduler":scheduler,
9 "keepSession":keepSession,
10 "keepSessionType":keepSessionType,
11 "keepSessionDuration":keepSessionDuration,
12 "keepSessionCookieName":keepSessionCookieName,
13 "xForwardFor":xForwardFor,
14 "xForwardedProto":xForwardedProto,
15 "additionalAttributes": {
16 "gzipJson": "on"
17 },
18 "healthCheckType":healthCheckType,
19 "healthCheckPort":healthCheckPort,
20 "healthCheckURI":healthCheckURI,
21 "healthCheckTimeoutInSecond":healthCheckTimeoutInSecond,
22 "healthCheckInterval":healthCheckInterval,
23 "unhealthyThreshold":unhealthyThreshold,
24 "healthyThreshold":healthyThreshold,
25 "healthCheckNormalStatus":healthCheckNormalStatus,
26 "healthCheckHost":healthCheckHost,
27 "serverTimeout":serverTimeout,
28 "redirectPort":redirectPort
29}
请求头域
除公共头域外,无其他特殊头域
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| version | String | 是 | URL参数 | API版本号,当前取值1 |
| clientToken | String | 否 | Query参数 | 幂等性Token,长度不超过64位 |
| blbId | String | 是 | URL参数 | 所属LoadBalancer的标识符 |
| listenerPort | int | 是 | RequestBody参数 | 监听器的监听端口,需为1-65535间的整数 |
| backendPort | int | 是 | RequestBody参数 | 后端服务器的监听端口,需为1-65535间的整数 |
| scheduler | String | 是 | RequestBody参数 | 负载均衡算法,支持2种方式:"RoundRobin"/"LeastConnection","RoundRobin"代表加权轮询、"LeastConnection"代表最小连接数 |
| keepSession | bool | 否 | RequestBody参数 | 是否开启会话保持功能,即同一个Client发出的请求都会到达同一个后端服务器,默认关闭 |
| keepSessionType | String | 否 | RequestBody参数 | 会话保持的cookie处理方式,当且仅当开启会话保持时有效,支持"insert"/"rewrite",默认"insert" |
| keepSessionDuration | int | 否 | RequestBody参数 | 会话保持的cookie有效时间(单位:秒),当且仅当开启会话保持时有效,默认3600s,需为1-15552000间的整数 |
| keepSessionCookieName | String | 否 | RequestBody参数 | 会话保持需要覆盖的cookie名称,当且仅当开启会话保持且keepSessionType="rewrite"时有效 |
| xForwardFor | bool | 否 | RequestBody参数 | 是否开启获取Client真实IP,开启后后端服务器上可以通过X-Forwarded-For这个HTTP Header来获得Client端的真实地址,默认关闭 |
| xForwardedProto | bool | 否 | RequestBody参数 | 将监听使用的协议通过 x-forwarded-proto HTTP Header 转发给后端服务器 |
| additionalAttributes | AdditionalAttributesModel | 否 | RequestBody参数 | HTTP类型监听器定制配置 |
| healthCheckType | String | 否 | RequestBody参数 | 健康检查协议,支持"HTTP"/"TCP",默认"HTTP" |
| healthCheckPort | int | 否 | RequestBody参数 | 健康检查端口,默认为backendPort |
| healthCheckURI | String | 否 | RequestBody参数 | 健康检查URI,默认/。当健康检查协议为"HTTP"时生效 |
| healthCheckTimeoutInSecond | int | 否 | RequestBody参数 | 健康检查超时(单位:秒),默认为3,需为1-60间的整数 |
| healthCheckInterval | int | 否 | RequestBody参数 | 健康检查间隔(单位:秒),默认为3,需为1-10间的整数 |
| unhealthyThreshold | int | 否 | RequestBody参数 | 不健康阈值,即连续多少次健康检查失败后,屏蔽该后端服务器。默认为3,需为2-5间的整数 |
| healthyThreshold | int | 否 | RequestBody参数 | 健康阈值,即连续多少次健康检查成功后,重新将该后端服务器置为可用。默认为3,需为2-5间的整数 |
| healthCheckNormalStatus | String | 否 | RequestBody参数 | 健康检查正常时的HTTP状态码,支持5类状态码的组合,例如"http_1xx|http_2xx",默认"http_2xx|http_3xx"。当健康检查协议为"HTTP"时生效 |
| healthCheckHost | String | 否 | RequestBody参数 | 7层健康检查请求的头部域会带指定的host字段,例如"localhost",默认""。当健康检查协议为"HTTP"时生效 |
| serverTimeout | int | 否 | RequestBody参数 | 后端服务器最大超时(单位:秒),默认30s,需为1-3600间的整数 |
| redirectPort | int | 否 | RequestBody参数 | 将此监听器收到的请求转发到HTTPS监听器,HTTPS监听器通过这个端口指定 |
返回头域
除公共头域外,无其他特殊头域
返回参数
无
请求示例
Text
1POST /v1/blb/lb-j8UqijYf/HTTPlistener?clientToken=asdfg HTTP/1.1
2Host: blb.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "listenerPort":95,
7 "backendPort":95,
8 "scheduler":"LeastConnection",
9 "healthCheckTimeoutInSecond":4,
10 "healthCheckInterval":5,
11 "unhealthyThreshold":2,
12 "xForwardFor":true,
13 "xForwardedProto":true,
14 "additionalAttributes": {
15 "gzipJson": "on"
16 },
17 "healthCheckType":"HTTP",
18 "serverTimeout":1800,
19 "healthCheckNormalStatus":"http_1xx|http_2xx",
20 "healthCheckHost":"localhost",
21 "redirectPort":80
22}
响应示例
Text
1HTTP/1.1 200 OK
2x-bce-request-id: 946002ee-cb4f-4aad-b686-5be55df27f09
3Date: Wed, 10 Apr 2016 08:26:52 GMT
4Transfer-Encoding: chunked
5Content-Type: application/json;charset=UTF-8
6Server: BWS
评价此篇文章
