This topic describes how to add an HTTP listener to a Classic Load Balancer (CLB) instance. HTTP is applicable to applications that must identify data from different sources, such as web applications and mobile games. You can add HTTP listeners to forward HTTP requests.

Prerequisites

A Classic Load Balancer (CLB) instance is created. For more information, see Create a CLB instance.

Step 1: Configure an HTTP listener

  1. Log on to the CLB console.
  2. Select the region where the CLB instance is deployed.
  3. Use one of the following methods to start the listener configuration wizard:
    • On the Instances page, find the CLB instance and click Configure Listener in the Actions column.
    • On the Instances page, click the ID of the CLB instance that you want to manage. On the Listener tab, click Add Listener.
  4. Set the following parameters and click Next.
    Parameter Description
    Select Listener Protocol Select the protocol of the listener.

    HTTP is selected in this example.

    Backend Protocol In this topic, HTTP is used, and Backend Protocol is set to HTTP.
    Listening Port Specify the listener port that is used to receive requests and forward them to backend servers. Valid values: 1 to 65535. HTTP uses port 80.
    Listener Name Specify a name for the custom listener. The description must be 1 to 256 characters in length, and can contain letters, digits, hyphens (-), forward slashes (/), periods (.),and underscores (_).
    Advanced Click Modify to configure advanced settings.
    Scheduling Algorithm Select a scheduling algorithm.
    • Weighted Round-Robin (WRR): Backend servers that have higher weights receive more requests than backend servers that have lower weights.
    • Round-Robin (RR): Requests are distributed to backend servers in sequence.
    Redirection Specify whether to redirect traffic from the HTTP listener to an HTTPS listener.
    Note Before you enable redirection, make sure that an HTTPS listener is created.
    Enable Session Persistence

    Specify whether to enable session persistence.

    After session persistence is enabled, CLB forwards all requests from the same client to the same backend server.

    CLB persists HTTP sessions based on cookies. CLB allows you to use the following methods to process cookies:

    • Insert cookie: If you select this option, you only need to specify the timeout period of the cookie.

      CLB 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.

    • Rewrite cookie: If you select this option, you can specify the cookie that you want to insert into an HTTP or HTTPS response. You must specify the timeout period and the lifetime of a cookie on a backend server.

      After you specify a cookie, CLB overwrites the original cookie with the specified cookie. The next time CLB receives a client request that carries the specified cookie, the listener distributes the request to the recorded backend server.

    Enable Access Control Specify whether to enable access control.

    Select an access control method after you enable access control. Then, select an access control list (ACL) that is used as the whitelist or blacklist of the listener.

    Note IPv6 instances can be associated only with IPv6 network ACLs, and IPv4 instances can be associated only with IPv4 network ACLs. For more information, see Create an access control list.
    Enable Peak Bandwidth Limit

    Specify whether to set a bandwidth limit for the listener. Unit: Mbit/s. Valid values: 0 to 5120.

    If a CLB instance is billed based on bandwidth usage, you can set different maximum bandwidth values for different listeners. This limits the amount of traffic that flows through each listener. The sum of the maximum bandwidth values of all listeners that are added to a CLB instance cannot exceed the maximum bandwidth value of the CLB instance. By default, this feature is disabled and all listeners share the bandwidth of the CLB instance.

    Note If a CLB instance is billed based on data transfer, the bandwidth of its listeners is not limited by default.
    Idle Timeout Specify the timeout period of idle connections. Unit: seconds. Valid values: 1 to 60.

    If no request is received within the specified timeout period, CLB closes the current connection. CLB creates a new connection when a new connection request is received.

    Request Timeout Specify the request timeout period. Unit: seconds. Valid values: 1 to 180.

    If no response is received from the backend server within the request timeout period, CLB returns an HTTP 504 error to the client.

    Enable Gzip Compression If you enable Gzip compression, files of specific types are compressed. If you disable Gzip compression, no file is compressed.

    Gzip supports the following file types: text/xml, text/plain, text/css, application/javascript, application/x-javascript, application/rss+xml, application/atom+xml, and application/xml.

    Add HTTP Header Fields You can add the following HTTP header fields:
    • X-Forwarded-For: Add the header field to retrieve the real IP address of the client.
    • SLB-ID: Add the header field to retrieve the ID of the CLB instance.
    • SLB-IP: Add the header field to retrieve the IP address of the CLB instance.
    • X-Forwarded-Proto: Add the header field to retrieve the listener protocol used by the CLB instance.
    • X-Forwarded-Port: Add the header field to retrieve the listener ports of the CLB instance.
    • X-Forwarded-Client-srcport: Add the header field to retrieve the port over which a client communicates with the CLB instance.
    Obtain Client Source IP Address Specify whether to retrieve the client IP address. By default, this feature is enabled.
    Automatically Enable Listener After Creation Specify whether to immediately enable the listener after it is created. By default, listeners are enabled after they are created.
    WAF Protection Specify whether to enable Web Application Firewall (WAF) protection.

Step 2: Add backend servers

After you configure the listener, you must add backend servers to process client requests. You can add backend servers to the default server group, or create a vServer group or primary/secondary server group, and then add servers to the server group. For more information, see Backend server overview.

Backend servers are added to the default server group in this example.

  1. On the Backend Servers wizard page, select Default Server Group. Then, click Add More.
  2. In the My Servers panel, select the Elastic Compute Service (ECS) instances that you want to add as backend servers and click Next.
  3. Set weights for the selected ECS instances in the Weight column.
    Note
    • An ECS instance with a higher weight receives more requests. The default weight is 100. You can click Reset to set the weight to the default value.
    • If you set the weight of a server to 0, the server does not receive requests.
  4. Click Add. On the Default Server Group tab, specify the ports that you want to open on the backend servers to receive requests. Valid values: 1 to 65535. Click Next.

    You can specify the same port on different backend servers that are added to a CLB instance.

Step 3: Configure health checks

CLB performs health checks to check the availability of the ECS instances that serve as backend servers. The health check feature improves overall service availability and reduces the impact of backend server failures.

On the Health Check wizard page, click Modify to modify the health check configurations. For more information, see Configure health check.

Step 4: Submit the configurations

  1. On the Confirm wizard page, check the configurations. You can click Modify to modify the configurations.
  2. After you confirm the configurations, click Submit.
  3. When Configuration Successful appears, click OK.

    After you configure the listener, you can view the listener on the Listener tab.