Configuring an HTTP Listener

Last updated: 2019-11-05 15:21:01

PDF

HTTP Listener Overview

You can create an HTTP listener to a CLB instance to forward HTTP requests from the client. HTTP is suitable for applications where request contents need to be identified, such as web applications and mobile apps.

Prerequisites

You need to create a CLB instance first.

Configuring an HTTP Listener

Step 1. Open the "Listener Management" page

  1. Log in to the CLB Console.
  2. Select Instance Management on the left sidebar.
  3. In the instance list, click the ID of the instance to be configured to enter the instance details page.
  4. Click the Listener Management tab or click Configure Listener in the "Operation" column.
  5. The "Listener Management" page is as shown below:

Step 2. Configure a listener

Click Create in HTTP/HTTPS Listener and configure an HTTP listener in the pop-up window.

1. Create a listener

Configuration Item Description Example
Name Listener name test-http-80
Listener protocol and listening port
  • Listener protocol: CLB supports various protocols, including TCP, UDP, TCP SSL, HTTP, and HTTPS. HTTP is used in this example.
  • Listening port: A port used to receive requests and forward them to the real server. Port range: 1-65535.
  • The listening port must be unique in the same CLB instance.
  • HTTP:80

    The specific configuration of the created HTTP listener is as shown below:

    2. Create a forwarding rule

    Configuration Item Description Example
    Domain name Request domain name.
  • Exact domain names are supported, such as www.example.com. Wildcard domain names are also supported, such as *.example.com and www.example.*, where * can appear only once in a single domain name.
  • A non-regular domain name can contain the following characters: a-z, 0-9, ., and -.
  • Regex is supported, but they cannot contain the following characters: ", {, }, ;, \, ```, ~, ', and space.
  • A domain name can contain 1-120 characters.
  • www.example.com
    URL path Request path.
  • The path is in the format of / by default, must begin with /, and can contain 1-120 characters.
  • A non-regular URL path must begin with / and can contain the following characters: a-z, A-Z, 0-9, ., -, /, =, and ?.
  • Regex is supported.
    1. Beginning with = indicates exact match.
    2. Beginning with ^~ indicates that the URI begins with a general string and is not regex match.
    3. Beginning with ~ indicates case-sensitive regex match.
    4. Beginning with ~* indicates non-case-sensitive regex match.
    5. / indicates generic match, where any requests will be matched if there are no other matches.
    6. A regular URL cannot contain the following characters: ", {, }, ;, \, ```, ~, ', and space.
    /index
    Balancing method For HTTP listeners, CLB supports three scheduling algorithms: weighted round robin (WRR), weighted least connections (WLC), and IP hash.
  • WRR: Requests are sequentially delivered to different real servers according to their weights. Scheduling is done based on the number of new connections, where servers with higher weights will undergo more polls (i.e., a higher probability), while servers with the same weight process the same number of connections.
  • WLC: Loads of servers are estimated according to the number of active connections to the servers. Scheduling is done based on server loads and weights. If their weights are the same, servers with fewer active connections will undergo more polls (i.e., a higher probability).
  • IP hash: Hash keys are used to locate the corresponding servers in the static hash table based on the source IPs of requests. If a server is available and not overloaded, requests will be delivered to it; otherwise, a null value will be returned.
  • WRR
    Getting client IP Enabled by default Enabled
    Gzip compression Enabled by default Enabled

    Select the HTTP listener for which to create a forwarding rule and click + on the right. The specific configuration is as shown below:

    3. Health check

    Configuration Item Description Example
    Health check status Health check can be enabled or disabled. In HTTP listeners, CLB instances send HTTP requests to the specified server port to perform health checks. Enabled
    Check domain name Request domain name.
  • The forwarding domain name is used for this parameter by default.
  • It can contain 1-120 supported characters: a-z, 0-9, ., and -.
  • Regex is not supported currently.
  • If a wildcard domain name is entered, a fixed domain name (non-regular) should be specified as the health check domain name.
  • Default value (i.e., www.example.com)
    Check path Request path.
  • The path is in the format of / by default and must begin with /.
  • It can contain 1-120 supported characters: a-z, 0-9, ., and -.
  • Regex is not supported currently.
  • It is recommended to specify a fixed URL path (static page) for health checks.
  • Default value (i.e., /)
    Check interval
  • Interval between two health checks.
  • Value range: 5-300s. Default value: 5s.
  • 5s
    Unhealthy threshold
  • If the health check results received n times (n is the entered number) in a row are failures, the instance will be considered unhealthy, and the status displayed in the console will be Abnormal.
  • Value range: 2-10. Default value: 3.
  • 3 times
    Healthy threshold
  • If the health check results received n times (n is the entered number) in a row are successes, the instance will be considered healthy, and the status displayed in the console will be Healthy.
  • Value range: 2-10. Default value: 3.
  • 3 times
    HTTP request method HTTP request method for health checks. Value range: GET, HEAD. Default value: GET.
  • If HEAD is used, the server will only return the HTTP header, which can reduce backend overheads and improve request efficiency; the corresponding real server needs to support HEAD.
  • If GET is used, the real server needs to support GET.
  • GET
    HTTP status code check If the status code is the selected one, the real server is considered alive (healthy). Value range: http_1xx, http_2xx, http_3xx, http_4xx, http_5xx. Multiple selections: http_1xx, http_2xx, http_3xx, http_4xx

    The specific configuration of health check is as shown below:

    4. Session persistence

    Configuration Item Description Example
    Session persistence status Session persistence can be enabled or disabled.
  • If session persistence is enabled, the CLB listener will deliver access requests from the same client to the same real server.
  • HTTP session persistence is implemented based on cookies, which are implanted into the client by the CLB instance.
  • Session persistence can be enabled for WRR scheduling but not WLC or IP hash scheduling.
  • Enabled
    Session persistence time Session persistence time.
  • If there is no new request in the connection within the session persistence time, session persistence will be interrupted automatically.
  • Value range: 30-3,600s.
  • 30s

    The specific configuration of session persistence is as shown below:

    Step 3. Bind a real server

    1. On the "Listener Management" page, select the created listener HTTP:80. Click + on the left to expand the domain names and URL paths, select the desired URL path, and view the real servers bound to the path on the right of the listener.
    2. Click Bind and select the real server to be bound and configure the server port and weight in the pop-up window.
      1. Add Port: In the "Selected" box on the right, click Add Port to add multiple ports for the same CVM instance, such as ports 80, 81, and 82.
      2. Default Port: Enter the "Default Port" first and then select the CVM instance. The port of every CVM instance is the default port.

    After these three steps are completed, the HTTP listener rule has been configured as shown below:

    Step 4. Security group (optional)

    You can configure a CLB security group to isolate public network traffic. For more information, see Configuring a CLB Security Group.

    Step 5. Modify/delete a listener (optional)

    If you need to modify or delete a created listener, click the listener/domain name/URL path on the "Listener Management" page and select Modify or Delete.