更新时间:2025-09-22 GMT+08:00

查询监听器详情

功能介绍

查询监听器详情。

调用方法

请参见如何调用API

URI

GET /v3/{project_id}/elb/listeners/{listener_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:项目ID。获取方式请参见获取项目ID

约束限制:不涉及

取值范围:长度为32个字符,由小写字母和数字组成。

默认取值:不涉及

listener_id

String

参数解释:监听器ID。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:IAM鉴权Token。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

响应参数

状态码:200

表3 响应Body参数

参数

参数类型

描述

request_id

String

参数解释:请求ID。

取值范围:由数字、小写字母和中划线(-)组成的字符串,自动生成。

listener

Listener object

参数解释:监听器对象。

表4 Listener

参数

参数类型

描述

admin_state_up

Boolean

参数解释:监听器的管理状态。

取值范围:true

client_ca_tls_container_ref

String

参数解释:监听器使用的CA证书ID。当且仅当type=client时,才会使用该字段对应的证书。

取值范围:不涉及

connection_limit

Integer

参数解释:监听器的最大连接数。

取值范围:大于等于-1的整数。

created_at

String

参数解释:监听器的创建时间。

取值范围:不涉及

格式:yyyy-MM-dd'T'HH:mm:ss'Z',如:2021-07-30T12:03:44Z

default_pool_id

String

参数解释:监听器的默认后端服务器组ID。当请求没有匹配的转发策略时,转发到默认后端服务器组上处理。

取值范围:不涉及

default_tls_container_ref

String

参数解释:监听器使用的服务器证书ID。

取值范围:不涉及

description

String

参数解释:监听器的描述信息。

取值范围:不涉及

http2_enable

Boolean

参数解释:客户端与LB之间的HTTPS请求的HTTP2功能的开启状态。

开启后,可提升客户端与LB间的访问性能,但LB与后端服务器间仍采用HTTP1.X协议。

取值范围:不涉及

id

String

参数解释:监听器ID。

取值范围:不涉及

insert_headers

ListenerInsertHeaders object

参数解释:附加的HTTP头字段,ELB会将特定的HTTP头字段写入到请求头中,并随报文传递到后端服务器。例如可通过X-Forwarded-ELB-IP开关,将负载均衡器的弹性公网IP传到后端服务器。

loadbalancers

Array of LoadBalancerRef objects

参数解释:监听器所属的负载均衡器的ID列表。实际上一个监听器只支持关联到一个LB。

name

String

参数解释:监听器的名称。若名称为空,则在控制台的监听器列表无法选择并查看监听器详情。

取值范围:不涉及

project_id

String

参数解释:监听器所在的项目ID。

取值范围:不涉及

enterprise_project_id

String

参数解释:企业项目ID。

取值范围:不涉及

protocol

String

参数解释:监听器的监听协议。

取值范围:TCP、UDP、HTTP、HTTPS、TERMINATED_HTTPS、QUIC、TLS。

protocol_port

Integer

参数解释:监听器的监听端口。

取值范围:不涉及

sni_container_refs

Array of strings

参数解释:监听器使用的SNI证书(带域名的服务器证书)ID列表。

取值范围:不涉及

sni_match_algo

String

参数解释:监听器使用的SNI证书泛域名匹配方式。

取值范围:longest_suffix表示最长尾缀匹配;wildcard表示标准域名分级匹配。

tags

Array of Tag objects

参数解释:标签列表。

updated_at

String

参数解释:监听器的更新时间。

取值范围

格式:yyyy-MM-dd'T'HH:mm:ss'Z',如:2021-07-30T12:03:44Z

tls_ciphers_policy

String

参数解释:监听器使用的安全策略。

取值范围:tls-1-0-inherit、tls-1-0、tls-1-1、tls-1-2、tls-1-2-strict、tls-1-2-fs、tls-1-0-with-1-3、tls-1-2-fs-with-1-3、hybrid-policy-1-0、tls-1-2-strict-no-cbc,默认:tls-1-2。

security_policy_id

String

参数解释:自定义安全策略的ID。

取值范围:不涉及

enable_member_retry

Boolean

参数解释:是否开启后端服务器的重试。

取值范围:true 开启重试,false 不开启重试。

keepalive_timeout

Integer

参数解释:客户端连接空闲超时时间。在超过keepalive_timeout时长一直没有请求,负载均衡会暂时中断当前连接,直到下一次请求时重新建立新的连接。

取值范围

  • TCP监听器:10-4000s。

  • 若为HTTP/HTTPS/TERMINATED_HTTPS监听器,取值范围为:0-4000s。

client_timeout

Integer

参数解释:等待客户端请求超时时间,包括两种情况:

  • 读取整个客户端请求头的超时时长:如果客户端未在超时时长内发送完整个请求头,则请求将被中断

  • 两个连续body体的数据包到达LB的时间间隔,超出client_timeout将会断开连接。

取值范围:1-300,单位:秒。

member_timeout

Integer

参数解释:等待后端服务器响应超时时间。请求转发后端服务器后,在等待超时member_timeout时长没有响应,负载均衡将终止等待,并返回HTTP504错误码。

取值范围:1-300,单位:秒。

ipgroup

ListenerIpGroup object

参数解释:listener对象中的ipgroup信息。

transparent_client_ip_enable

Boolean

参数解释:是否透传客户端IP地址。开启后客户端IP地址将透传到后端服务器。

仅作用于共享型LB的TCP/UDP监听器。

取值范围

  • 共享型LB的TCP/UDP监听器可设置为true或false,不传默认为false。

  • 共享型LB的HTTP/HTTPS监听器只支持设置为true,不传默认为true。

  • 独享型负载均衡器所有协议的监听器只支持设置为true,不传默认为true。

proxy_protocol_enable

Boolean

参数解释:是否开启proxy_protocol。仅TLS监听器可指定,其他协议的监听器该字段不生效,proxy_protocol不开启。

取值范围:true 开启,false 不开启。

enhance_l7policy_enable

Boolean

参数解释:是否开启高级转发策略功能。开启高级转发策略后,支持更灵活的转发策略和转发规则设置。

开启后支持如下场景:

  • 转发策略的action字段支持指定为REDIRECT_TO_URL、FIXED_RESPONSE,即支持URL重定向和响应固定的内容给客户端。

  • 转发策略支持指定priority、redirect_url_config、fixed_response_config字段。

  • 转发规则rule的type可以指定METHOD, HEADER, QUERY_STRING, SOURCE_IP这几种取值。

  • 转发规则rule的type为HOST_NAME时,转发规则rule的value支持通配符*。

  • 转发规则支持指定conditions字段。

取值范围:true开启,false不开启。

quic_config

ListenerQuicConfig object

参数解释:当前监听器关联的QUIC监听器配置信息。

protection_status

String

参数解释:修改保护状态。

取值范围

  • nonProtection: 不保护。

  • consoleProtection: 控制台修改保护。

protection_reason

String

参数解释:设置保护的原因。作为protection_status的转态设置的原因。

取值范围:除'<'和'>'外通用Unicode字符集字符,最大255个字符。

gzip_enable

Boolean

参数解释:ELB是否开启gzip压缩。

取值范围:true开启,false不开启。

port_ranges

Array of PortRange objects

参数解释:全端口监听,指定端口监听范围(闭区间)。

ssl_early_data_enable

Boolean

参数解释:监听器0-RTT能力开关

约束限制:仅HTTPS类型监听器支持配置,需要依赖TLSv1.3安全策略协议。

cps

Integer

参数解释:监听器新建限速。当该限速值大于LB的限速值时,以LB的限速值生效。

取值范围:0-1000000

connection

Integer

参数解释:监听器并发限速。当该限速值大于LB的限速值时,以LB的限速值生效。

取值范围:0-1000000

nat64_enable

Boolean

参数解释:监听器地址转换能力开关,可以实现客户端通过访问LB的IPv4或者IPv6地址,来访问IPv4后端和IPv6后端。

取值范围

  • true:开启地址转换功能。

  • false:关闭地址转换功能。

表5 ListenerInsertHeaders

参数

参数类型

描述

X-Forwarded-ELB-IP

Boolean

参数解释:X-Forwarded-ELB-IP设为true可以将ELB实例的eip地址从报文的http头中带到后端服务器。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

X-Forwarded-Port

Boolean

参数解释:X-Forwarded-Port设为true可以将ELB实例的监听端口从报文的http头中带到后端服务器。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

X-Forwarded-For-Port

Boolean

参数解释:X-Forwarded-For-Port设为true可以将客户端的源端口从报文的http头中带到后端服务器。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

X-Forwarded-Host

Boolean

参数解释:X-Forwarded-Host设为true可以将客户请求头的X-Forwarded-Host设置为请求头的Host带到后端服务器。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

X-Forwarded-Proto

Boolean

参数解释:X-Forwarded-Proto设为true可以将负载均衡器实例的监听协议通过报文的http头带到后端服务器。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

X-Real-IP

Boolean

参数解释:X-Real-IP设为true可以将客户端的IP通过报文的http头带到后端服务器。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

X-Forwarded-ELB-ID

Boolean

参数解释:X-Forwarded-ELB-ID设为true可以将负载均衡器实例的ID通过报文的http头带到后端服务器。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

X-Forwarded-TLS-Certificate-ID

Boolean

参数解释:X-Forwarded-TLS-Certificate-ID设为true可以将负载均衡器实例的证书ID通过报文的http头带到后端服务器。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

X-Forwarded-TLS-Protocol

Boolean

参数解释:X-Forwarded-TLS-Protocol设为true可以将负载均衡器实例的算法协议通过报文的http头带到后端服务器。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

X-Forwarded-TLS-Cipher

Boolean

参数解释:X-Forwarded-TLS-Cipher设为true可以将负载均衡器实例的算法套件通过报文的http头带到后端服务器。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

表6 LoadBalancerRef

参数

参数类型

描述

id

String

参数解释:负载均衡器ID。

取值范围:不涉及

表7 Tag

参数

参数类型

描述

key

String

参数解释:标签键。

取值范围:不涉及

value

String

参数解释:标签值。

取值范围:不涉及

表8 ListenerIpGroup

参数

参数类型

描述

ipgroup_id

String

参数解释:监听器关联的访问控制组的id。

创建时必选,更新时非必选。

约束限制

指定的ipgroup必须已存在,不能指定为null,否则与enable_ipgroup冲突。

enable_ipgroup

Boolean

参数解释:访问控制组的状态。

开启访问控制的监听器,允许直接删除。

取值范围

  • true:开启访问控制。

  • false:关闭访问控制。

type

String

参数解释:访问控制组的类型。

取值范围

  • white:白名单,只允许指定ip访问。

  • black:黑名单,不允许指定ip访问。

表9 ListenerQuicConfig

参数

参数类型

描述

quic_listener_id

String

参数解释:监听器关联的QUIC监听器ID。

取值范围:不涉及

enable_quic_upgrade

Boolean

参数解释:QUIC升级的开启状态。开启HTTPS监听器升级QUIC监听器能力。

取值范围

  • true:开启QUIC升级。

  • false:关闭QUIC升级。

表10 PortRange

参数

参数类型

描述

start_port

Integer

参数解释:起始端口。

约束限制:不涉及

取值范围:1-65535

**默认取值:不涉及

end_port

Integer

参数解释:结束端口,需大于等于起始端口

约束限制:不涉及

取值范围:1-65535

**默认取值:不涉及

请求示例

查询监听器详情

GET https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/listeners/0b11747a-b139-492f-9692-2df0b1c87193

响应示例

状态码:200

操作正常返回。

{
  "listener" : {
    "id" : "0b11747a-b139-492f-9692-2df0b1c87193",
    "name" : "My listener",
    "protocol_port" : 80,
    "protocol" : "TCP",
    "ipgroup" : null,
    "description" : "My listener update.",
    "default_tls_container_ref" : null,
    "admin_state_up" : true,
    "loadbalancers" : [ {
      "id" : "098b2f68-af1c-41a9-8efd-69958722af62"
    } ],
    "member_timeout" : null,
    "client_timeout" : null,
    "keepalive_timeout" : 300,
    "client_ca_tls_container_ref" : null,
    "project_id" : "99a3fff0d03c428eac3678da6a7d0f24",
    "sni_container_refs" : [ ],
    "connection_limit" : -1,
    "default_pool_id" : null,
    "tls_ciphers_policy" : "tls-1-0",
    "tags" : [ ],
    "created_at" : "2019-04-02T00:12:32Z",
    "updated_at" : "2019-04-02T17:43:46Z",
    "http2_enable" : true,
    "insert_headers" : {
      "X-Forwarded-ELB-IP" : true
    },
    "transparent_client_ip_enable" : false,
    "nat64_enable" : false
  },
  "request_id" : "1394eb39-e4c8-4177-b96d-aaff569f1833"
}

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
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
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.elb.v3.region.ElbRegion;
import com.huaweicloud.sdk.elb.v3.*;
import com.huaweicloud.sdk.elb.v3.model.*;


public class ShowListenerSolution {

    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");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        ElbClient client = ElbClient.newBuilder()
                .withCredential(auth)
                .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                .build();
        ShowListenerRequest request = new ShowListenerRequest();
        request.withListenerId("{listener_id}");
        try {
            ShowListenerResponse response = client.showListener(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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkelb.v3.region.elb_region import ElbRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkelb.v3 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"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = ElbClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(ElbRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ShowListenerRequest()
        request.listener_id = "{listener_id}"
        response = client.show_listener(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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/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")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := elb.NewElbClient(
        elb.ElbClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ShowListenerRequest{}
	request.ListenerId = "{listener_id}"
	response, err := client.ShowListener(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

操作正常返回。

错误码

请参见错误码