Creates an HTTP listener.

Note Newly created listeners are in the stopped state. After a listener is created, you can call the StartLoadBalancerListener operation to start the listener. After the listener is started, the listener can forward traffic to backend servers.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes CreateLoadBalancerHTTPListener

The operation that you want to perform.

Set the value to CreateLoadBalancerHTTPListener.

HealthCheck String Yes on

Specifies whether to enable health checks. Valid values:

  • on: enables health checks.
  • off: disables health checks.
ListenerPort Integer Yes 80

The frontend port that is used by the Server Load Balancer (SLB) instance.

Valid values: 1 to 65535.

LoadBalancerId String Yes lb-bp1c9vixxjh92q83tw*****

The ID of the SLB instance.

StickySession String Yes off

Specifies whether to enable session persistence. Valid values:

  • on: enables session persistence.
  • off: disables session persistence.
RegionId String Yes cn-hangzhou

The ID of the region where the SLB instance is deployed.

You can query region IDs from the Regions and zones list or by calling the DescribeRegions operation.

Bandwidth Integer No -1

The bandwidth limit of the listener. Valid values:

  • -1: If you set the value to -1, the bandwidth of the listener is unlimited.
  • 1 to 5120: If you set the value to a number from 1 to 5120, the value that you specify indicates the bandwidth limit of the listener. The sum of bandwidth limit values that you specify for all listeners of the SLB instance cannot exceed the bandwidth limit of the SLB instance.
Note This parameter applies only to mainland China.
BackendServerPort Integer No 80

The backend port that is used by the SLB instance.

Valid values: 1 to 65535.

Note If the VServerGroupId parameter is not set, this parameter is required.
XForwardedFor String No on

Specifies whether to use the X-Forwarded-For header to obtain the real IP address of the client.

Valid values: on and off. Default value: off.

Scheduler String No wrr

The scheduling algorithm. Valid values:

  • wrr: Backend servers that have higher weights receive more requests than those that have lower weights. This is the default value.
  • wlc: Requests are distributed based on the weights and number of connections to backend servers. If two backend servers have the same weight, the backend server that has fewer connections receives more requests.
  • rr: Requests are distributed to backend servers in sequence.
StickySessionType String No insert

The method that is used to handle a cookie. Valid values:

  • insert: inserts a cookie.

    SLB inserts a cookie (SERVERID) into the first HTTP or HTTPS response that is sent to a client. The next request from the client will contain this cookie, and the listener will forward this request to the recorded backend server.

  • server: rewrites a cookie.

    When SLB detects a user-defined cookie, it overwrites the original cookie with the user-defined cookie. The next request from the client will contain the user-defined cookie. Then, the listener will forward the request to the recorded backend server.
    Note If you set the StickySession parameter to on, this parameter is required.
CookieTimeout Integer No 500

The timeout period of a cookie.

Valid values: 1 to 86400. Unit: seconds.

Note If you set the StickySession parameter to on and the StickySessionType parameter to insert, this parameter is required.
Cookie String No B490B5EBF6F3CD402E515D22BCDA1598

The cookie to be configured on the backend server.

The value must be 1 to 200 characters in length, and can contain only ASCII characters and digits. It cannot contain commas (,), semicolons (;), or space characters. It cannot start with a dollar sign ($).

Note If you set the StickySession parameter to on and the StickySessionType parameter to server, this parameter is required.
HealthCheckDomain String No 172.16.**.**

The domain name that is used for health checks. Valid values:

  • $_ip: The private IP address of the backend server. If the $_ip parameter is set or the HealthCheckDomain parameter is not set, SLB uses the private IP addresses of backend servers as the domain names for health checks.
  • domain: The domain name must be 1 to 80 characters in length, and can contain only letters, digits, periods (.),and hyphens (-).
Note This parameter takes effect only when the HealthCheck parameter is set to on.
HealthCheckURI String No /test/index.html

The URL that is used for health checks.

The value must be 1 to 80 characters in length, and can contain only letters, digits, hyphens (-), forward slashes (/), periods (.), percent signs (%), question marks (?), number signs (#), and ampersands (&). The URL must not be a single forward slash (/). However, it must start with a forward slash (/).

Note This parameter takes effect only when the HealthCheck parameter is set to on.
HealthyThreshold Integer No 4

Specifies the number of successful health checks that must be consecutively performed before a backend server can be declared healthy (from fail to success).

Valid values: 2 to 10.

Note This parameter takes effect only when the HealthCheck parameter is set to on.
UnhealthyThreshold Integer No 4

Specifies the number of failed health checks that must be consecutively performed before a backend server can be declared unhealthy (from success to fail).

Valid values: 2 to 10.

Note This parameter takes effect only when the HealthCheck parameter is set to on.
HealthCheckTimeout Integer No 3

The timeout period of a health check response. If a backend Elastic Compute Service (ECS) instance does not respond within the specified timeout period, the health check fails. This parameter takes effect only when the HealthCheck parameter is set to on.

Valid values: 1 to 300. Unit: seconds.

Note If the value of the HealthCHeckTimeout parameter is smaller than that of the HealthCheckInterval parameter, the value of the HealthCHeckTimeout parameter is invalid and the value of the HealthCheckInterval parameter is used as the timeout period.
HealthCheckConnectPort Integer No 80

The port of the backend server that is used for health checks.

Valid values: 1 to 65535.

Note This parameter takes effect only when the HealthCheck parameter is set to on.
HealthCheckInterval Integer No 5

The time interval between two consecutive health checks.

Valid values: 1 to 50. Unit: seconds.

Note This parameter takes effect only when the HealthCheck parameter is set to on.
HealthCheckHttpCode String No http_2xx

The HTTP status code that indicates a successful health check. Separate multiple HTTP status codes with commas (,).

Default value: http_2xx.

Valid values: http_2xx, http_3xx, http_4xx, and http_5xx.

Note This parameter takes effect only when the HealthCheck parameter is set to on.
VServerGroupId String No rsp-cige6j*****

The ID of the vServer group.

XForwardedFor_SLBIP String No on

Specifies whether to use the SLB-IP header to obtain the real IP address of the client.

Valid values: on and off. Default value: off.

XForwardedFor_SLBID String No on

Specifies whether to use the SLB-ID header to obtain the ID of the SLB instance.

Valid values: on and off. Default value: off.

XForwardedFor_proto String No on

Specifies whether to use the X-Forwarded-Proto header to obtain the listener protocol of the SLB instance.

Valid values: on and off. Default value: off.

Gzip String No on

Specifies whether to enable gzip compression to compress types of files. Default value: on.

Valid values: on and off. Default value: off.

AclId String No 123

The ID of the network access control list (ACL) that is associated with the listener.

This parameter is required when the AclStatus parameter is set to on.

AclType String No white

The type of network ACL. Valid values:

  • white: a whitelist. The listener forwards only requests from the IP addresses and CIDR blocks that are added to a whitelist. Whitelists are used to allow access from specific IP addresses to an application.

    Risks may arise if you specify a whitelist.

    After you configure a whitelist for a listener, only requests from IP addresses that are added to the whitelist can be forwarded by the listener.

    If you enable a whitelist but do not specify IP addresses, the listener does not forward requests.

  • black: a blacklist. The listener does not forward requests from the IP addresses or CIDR blocks that are added to a blacklist. Blacklists are used to deny access from specific IP addresses to an application.

    If you enable a blacklist but do not specify IP addresses, the listener forwards all requests.

This parameter takes effect when the AclStatus parameter is set to on.

AclStatus String No off

Specifies whether to enable access control for the listener.

Valid values: on and off. Default value: off.

Description String No ListenerDescription

The description of the listener.

The description must be 1 to 80 characters in length, and can contain letters, digits, hyphens (-), forward slashes (/), periods (.),and underscores (_).

ListenerForward String No off

Specifies whether to enable HTTP-to-HTTPS redirection.

Valid values: on and off. Default value: off.

ForwardPort Integer No 443

The listening port that is used to redirect HTTP requests to HTTPS.

IdleTimeout Integer No 3

The timeout period of an idle connection. Unit: seconds. Valid values: 1 to 60. Default value: 15.

If no request is received within the specified timeout period, SLB closes the connection. When another request is received, SLB establishes a new connection.

RequestTimeout Integer No 6

The timeout period of a request. Unit: seconds. Valid values: 1 to 180. Default value: 60.

If no response is received from the backend server within the specified timeout period, SLB sends an HTTP 504 error to the client.

Response parameters

Parameter Type Example Description
RequestId String CEF72CEB-54B6-4AE8-B225-F876FF7BA984

The ID of the request.

Examples

Sample requests

http(s)://[Endpoint]/?Action=CreateLoadBalancerHTTPListener
&HealthCheck=off
&ListenerPort=80
&LoadBalancerId=lb-bp1c9vixxjh92q83tw*****
&StickySession=off
&BackendServerPort=80
&<Common request parameters>

Sample success responses

XML format

<CreateLoadBalancerHTTPListenerResponse>
	  <RequestId>1FF504CB-BFFF-4508-A51A-58A416604FC8</RequestId>
</CreateLoadBalancerHTTPListenerResponse>

JSON format

{
    "RequestId": "1FF504CB-BFFF-4508-A51A-58A416604FC8"
}

Error codes

For a list of error codes, visit the API Error Center.