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 users, such as web applications and mobile games. You can add HTTP listeners to forward HTTP requests.
A CLB instance is created. For more information, see Create a CLB instance.
Step 1: Configure an HTTP listener
- Log on to the CLB console.
- Select the region where the CLB instance is deployed.
- Use one of the following methods to open the listener configuration wizard:
- On the Instances page, find the CLB instance that you want to manage 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.
- Set the following parameters to configure the listener.
Parameter Description Select Listener Protocol Select a protocol for the listener.
In this example, HTTP is selected.
Listening Port Enter the port on which the CLB instance listens. The CLB instance uses the port to receive requests and forward the requests to backend servers. Valid values: 1 to 65535. Listener Name Enter a name for the listener. 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 those that have lower weights.
- Round-Robin (RR): Requests are evenly and sequentially distributed to backend servers.
Redirection Specify whether to redirect traffic from the HTTP listener to an HTTPS listener.Note Before you enable redirection, make sure that you have created an HTTPS listener. Enable Session Persistence
Specify whether to enable session persistence.
After session persistence is enabled, CLB forwards all requests from a client to the same backend server.
CLB maintains the persistence of HTTP sessions based on cookies. CLB allows you to use the following methods to process cookies:
- Insert cookie: If you select this option, you need only 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 contains the cookie. Then, the listener distributes the 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 lifecycle of the
cookie on the 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 with only IPv6 ACLs, while IPv4 instances can be associated only with IPv4 ACLs. For more information, see Create an access control list.
- Whitelist: Only requests from the IP addresses or CIDR blocks in the specified ACL
are forwarded. Whitelists apply to scenarios that require you to allow only specific IP addresses
to access 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 the whitelist does not contain an IP address, the CLB listener does not forward requests.
- Blacklist: Requests from the IP addresses or CIDR blocks in the specified ACL are
not forwarded. You can use the blacklist feature when you want to deny access from specified IP
If you enable a blacklist but the blacklist does not contain an IP address, the CLB listener forwards all requests.
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 bandwidth limit values for different listeners. This limits the amount of traffic that flows through each listener. The sum of the bandwidth limit values of all listeners that are added to a CLB instance cannot exceed the bandwidth of this 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 the amount of data transfer, the bandwidth of its listeners is not automatically limited.
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 connection. CLB recreates the 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 Specify whether to enable Gzip compression for a specified file type.
Add HTTP Header Fields You can add the following HTTP header fields:
- Use the
X-Forwarded-Forheader field to retrieve the real IP addresses of clients.
- Use the
SLB-IDheader field to retrieve the ID of the CLB instance.
- Use the
SLB-IPheader field to retrieve the public IP address of the CLB instance.
- Use the
X-Forwarded-Protoheader field to retrieve the listener protocol used by the CLB instance.
Obtain Client Source IP Address Specify whether to retrieve the real IP address of the client. By default, this feature is enabled. Automatically Enable Listener After Creation Specify whether to immediately enable the listener after it is created. By default, this feature is enabled.
- Click Next.
Step 2: Add backend servers
After you configure the listener, you must add backend servers to process client requests. You can use the default server group that is configured for the CLB instance. You can also create a vServer group or a primary/secondary server group. For more information, see Backend server overview.
The default server group is selected in this example.
- On the Backend Servers wizard page, select Default Server Group. Then, click Add More.
- In the My Servers panel, select the Elastic Compute Service (ECS) instances that you want to add as backend servers and click Next.
- On the Configure Ports and Weights wizard page, specify the weights of the backend servers that you want to add. A backend
server with a higher weight receives more requests. Note If the weight of a backend server is set to 0, no request is distributed to the backend server.
- Click Add. On the Default Server Group tab, specify the ports that you want to open on the
backend servers (ECS instances) to receive requests. Valid values: 1 to 65535.
You can specify the same port on different backend servers that are added to a CLB instance.
- Click Next.
Step 3: Configure health checks
SLB checks the availability of Elastic Compute Service (ECS) instances that serve as backend servers by performing health checks. The health check feature improves the overall availability of your frontend business and mitigates the impacts of exceptions that occur on backend ECS instances. Click Modify to modify the configurations of health checks. For more information, see Health check overview.
Step 4: Confirm the configurations
Perform the following steps to confirm the configurations.
- In the Confirm step, check the configurations. You can click Modify to modify the configurations.
- After you confirm the configurations, click Submit.
- In the Configuration Successful message, click OK.
You can check the created listener on the Listener tab.