This topic describes how to add an HTTP listener to an SLB instance. HTTP is applicable to the applications that need to identify data content, such as web applications and small-sized mobile games. You can add an HTTP listener to forward HTTP requests.
An SLB instance is created. For more information, see Create an SLB instance.
Step 1: Start the listener configuration wizard
To start the listener configuration wizard, perform the following operations:
- Log on to the Server Load Balancer console.
- In the left-side navigation pane, choose .
- Select the region of the target SLB instance.
- Use one of the following methods to start the listener configuration wizard:
- On the Server Load Balancers page, find the target SLB instance and then click Configure Listener in the Actions column.
- On the Server Load Balancers page, click the ID of the target SLB instance. On the Listener tab, click Add Listener.
Step 2: Configure the HTTP listener
Perform the following operations to configure the HTTP listener.
- In the Protocol and Listener step, specify the following information:
Parameter Description Select Listener Protocol Select the protocol of the listener.
In this example, select HTTP.
Listening Port Set the listening port used to receive requests and forward them to backend servers.
Valid values: 1 to 65535.Note The HTTP listening ports must be unique in an SLB instance.
Advanced Settings Scheduling Algorithm SLB supports three scheduling algorithms: RR, WRR, and WLC.
- Weighted Round-Robin (WRR): Backend servers with higher weights receive more requests.
- Round-Robin (RR): Requests are evenly and sequentially distributed to backend servers.
- Weighted Least Connections (WLC): Requests are distributed based on the combination of the weights and active connections of backend servers. Requests are distributed to the backend server with the least number of active connections. If two backend servers have the same number of active connections, the backend server with a higher weight receives more requests.
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, the listener forwards all requests from the same client to a specific backend server for the duration of a session.
HTTP implements cookie-based session persistence. You can choose from the following approaches to configure session persistence with cookies:
- Insert cookie: You only need to specify the cookie timeout period.
SLB inserts a cookie (SERVERID) to the first HTTP or HTTPS response packet sent to a client. The next request from the client will contain this cookie, and the listener will distribute this request to the recorded backend server.
- Rewrite cookie: You can specify the cookie to be inserted into the HTTP or HTTPS response. You must
specify the timeout period and lifecycle of this cookie on the backend server.
SLB rewrites the original cookie when the new cookie is detected. The next request that contains the new cookie will be distributed to the recorded backend server. For more information, see Configure session persistence.
Enable Access Control Specify whether to configure the listener to restrict access. Access Control Method
Select an access control method after you enable access control.
- Whitelist: Only the requests from the IP addresses or CIDR blocks in the specified ACL are
forwarded. You can use the whitelist feature when you want to allow access from specified
Using the whitelist feature may pose risks to your services. The whitelist allows only the traffic from the IP addresses in the specified ACL to access the SLB listener. If the whitelist is used while the corresponding ACL does not contain any IP addresses, the SLB listener forwards all access 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 addresses.
If the blacklist is used while the corresponding ACL does not contain any IP addresses, the SLB listener forwards all access requests.
Access Control List Select an ACL that functions as the whitelist or blacklist of the listener.Note IPv6 instances can only be associated with IPv6 ACLs, and IPv4 instances can only be associated with IPv4 ACLs. For more information, see Configure an access control list. Enable Peak Bandwidth Limit
You can switch on this option and then set a bandwidth limit for the listener.
If an SLB instance incurs fees based on the bandwidth, you can set different peak bandwidth values for different listeners to limit the amount of traffic that flows in each listener. The sum of the peak bandwidth values of all listeners added to an SLB instance cannot exceed the bandwidth of this SLB instance.
By default, this feature is disabled and all listeners share the bandwidth of the SLB instance.Note If an SLB instance incurs fees based on the amount of transmitted data, no peak bandwidth limit is applied by default.
Idle Timeout Specify the idle timeout period of connections. Unit: seconds. Valid values: 1 to 60.
If no request is received during the idle timeout period, SLB closes the connection and will restart the connection when the next request is received.This feature is available in all regions.Note This feature is unavailable for HTTP/2 requests.
Request Timeout Specify the request timeout period. Unit: seconds. Valid values: 1 to 180.
If no response is received from the backend server during the request timeout period, SLB sends an HTTP 504 error code to the client.
This feature is available in all regions.
Enable Gzip Compression Specify whether to enable compression for a specific file type.
Add HTTP Header Fields Select one or more custom HTTP header fields that you want to add:
- Use the
X-Forwarded-Forheader field to retrieve the IP addresses of clients.
- Use the
X-Forwarded-Protoheader field to retrieve the listener protocol used by the SLB instance.
- Use the
SLB-IPheader field to retrieve the public IP address of the SLB instance.
- Use the
SLB-IDheader field to retrieve the ID of the SLB instance.
Obtain Client Source IP Address HTTP listeners use the X-Forwarded-For header field to identify the originating IP addresses of clients. Automatically Enable Listener After Creation Specify whether to start the listener after the listener is configured. By default, the listener is started after configuration.
- Click Next.
Step 3: 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 VServer groups or primary/secondary server groups and then add servers to them. For more information, see Backend server overview.
This example adds backend servers to the default server group.
- Select Default Server Group and click Add More.
- Select ECS instances (backend servers) that you want to add, and then click Next.
- Configure weights for the added backend servers. A backend server with a higher weight receives more requests.Note If the weight of a backend server is set to 0, the backend server does not receive new requests.
- Click Add. On the Default Server Group tab, configure ports for the backend servers.Set a port for each backend server to receive requests. Valid values: 1 to 65535. You can specify the same port for multiple backend servers of an SLB instance.
- Click Next.
Step 4: Configure the health check
SLB checks the availability of backend servers by performing the health check. The health check feature improves the availability of frontend services by minimizing downtime caused by health issues of backend servers. Click Modify to configure advanced health check settings. For more information, see Health check overview.
Step 5: Confirm the settings
Complete the following steps to confirm and apply the listener settings:
- In the Submit step, check the configuration. You can click Modify to modify configuration settings.
- Click Submit.
- In the Configure Successful dialog box, click OK.
You can check the created listener on the Listener tab.