This topic describes how to add an HTTP listener to a Server Load Balancer (SLB) instance. The HTTP protocol is applicable for scenarios where data needs to be read, such as web applications and small 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 Open the listener configuration wizard
To open 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 where the target SLB instance resides.
- Use one of the following methods to open the listener configuration wizard:
- On the Server Load Balancers page, find the target 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
To configure the HTTP listener, follow these steps:
- On the Protocol and Listener page, configure the HTTP listener according to the following information:
Configuration Description Select Listener Protocol Select the protocol type of the listener.
In this topic, select HTTP.
Listening Port The listening port used to receive requests and forward the requests to backend servers.
Value range: 1 to 65535.Note The listening port must be unique in an SLB instance.
Advanced configurations Scheduling Algorithm SLB supports three scheduling algorithms: round robin, weighted round robin (WRR), and weighted least connections (WLC).
- Weighted Round-Robin (WRR): A backend server with a higher weight receives more requests.
- Round-Robin (RR): Requests are evenly and sequentially distributed to backend servers.
- Weighted Least Connections (WLC): A server with a higher weight receives more requests. When the weight values of two backend servers are the same, the backend server with a smaller number of connections is more likely to be polled.
Redirection Select whether to forward traffic of the HTTP listener to an HTTPS listener.Note Before you enable the redirection function, make sure that you have created an HTTPS listener. Enable Session Persistence
Select whether to enable session persistence.
After you enable session persistence, all session requests from the same client are sent to the same backend server.
HTTP session persistence is based on cookies. The following two methods are supported:
- Insert cookie: You only need to specify the cookie timeout period.
SLB adds a cookie to the first response from the backend server (inserts SERVERID in the HTTP and HTTPS response packet). The next request will contain the cookie and the listener will distribute the request to the same backend server.
- Rewrite cookie: You can set the cookie inserted to the HTTP or HTTPS response according to your
needs. You must maintain the timeout period and lifespan of the cookie on the backend
SLB will overwrite the original cookie when it discovers that a new cookie is set. The next time the client carries the new cookie to access SLB, the listener will distribute the request to the recorded backend server. For more information, see Configure session persistence.
Enable Access Control Select whether to enable the access control function. Access Control Method
Select an access control method after you enable the access control function:
- Whitelist: Only requests from IP addresses or CIDR blocks in the selected access control list
are forwarded. It applies to scenarios where the application only allows access from
some specific IP addresses.
Enabling a whitelist poses some risks to your services. After a whitelist is configured, only the IP addresses in the list can access the listener. If you enable the whitelist without adding any IP addresses in the corresponding access control list, all requests are forwarded.
- Blacklist: Requests from IP addresses or CIDR blocks in the selected access control list are
not forwarded. It applies to scenarios where the application only denies access from
some specific IP addresses.
If you enable a blacklist without adding any IP addresses in the corresponding access control list, all requests are forwarded.
Access Control List Select an access control list as the whitelist or the blacklist.Note An IPv6 SLB instance can only be associated with IPv6 access control lists and an IPv4 SLB instance can only be associated with IPv4 access control lists. For more information, see Creates an access control list. Enable Peak Bandwidth Limit
Select whether to configure the listener bandwidth.
If the SLB instance incurs charges based on bandwidth, you can set different peak bandwidth values for different listeners to limit the traffic passing through each listener. The sum of the peak bandwidth values of all listeners under an SLB instance cannot exceed the bandwidth value of that SLB instance.
This parameter is disabled by default, and all listeners share the total bandwidth of the SLB instance.Note SLB instances billed by traffic have no peak bandwidth limit by default.
Idle Timeout Specify the timeout period of the idle connection. Value range: 1 to 60. Unit: seconds.
If no request is received during the specified timeout period, SLB temporarily terminates the connection and restarts the connection when the next request is received.This function is available in all regions.Note This function does not work for HTTP/2.0 requests.
Request Timeout Specify the request timeout period. Value range: 1 to 180. Unit: seconds.
If no response is received from the backend server during the specified timeout period, SLB stops waiting and sends an HTTP 504 error code to the client.
This function is available in all regions.
Enable Gzip Compression Choose whether to enable Gzip compression to compress files of specific formats.
Add HTTP Header Fields Select the custom HTTP headers that you want to add:
- Use the
X-Forwarded-Forfield to retrieve the source IP address of the client.
- Use the
X-Forwarded-Protofield to retrieve the listener protocol used by the SLB instance.
- Use the
SLB-IPfield to retrieve the public IP address of the SLB instance.
- Use the
SLB-IDfield to retrieve the ID of the SLB instance.
Get Client Source IP Address HTTP listeners use X-Forwarded-For to obtain real IP addresses of clients. Automatically Enable Listener After Creation Choose whether to start the listener after the listener is configured. The listener is started by default.
- Click Next.
Step 3 Add backend servers
After configuring the listener, you must add backend servers to process client requests. You can use the default server group configured for the SLB instance, or configure a VServer group or a primary/secondary server group. For more information, see Backend server overview.
This example uses the default server group.
- Select Default Server Group, and click Add More.
- Select the ECS instances to be added, and then click Next.
- Configure ports and weights for the added backend servers (ECS instances).
The port on a backend server to receive requests. The port number is in the range of 1 to 65535. Port numbers of backend servers can be the same in an SLB instance.
The weight of a backend server. 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 will not receive new requests.
- Click Next.
Step 4 Configure health checks
SLB checks the service availability of backend servers by performing health checks. The health check feature improves the overall availability of frontend business and avoids the impact of exceptions occurring on backend servers. Click Modify to modify health check configurations. For more information, see Health check overview.
Step 5 Submit the configurations
Submit the configurations by performing the following steps:
- In the Submit step, check the configurations. You can click Modify to modify the configurations.
- Click Submit.
- In the Configuration Successful dialog box, click OK.
After successful configuration, you can view the created listener on the Listener tab.