Add a HTTP listener
Overview
This topic describes how to add an HTTP listener to a Server Load Balancer( SLB) instance. HTTP is applicable to applications that must identify data from different users, such as web applications and mobile games. You can add an HTTP listener to forward HTTP requests.
Procedure
- On the SLB management console page, select the SLB instance to be operated and click Configure Listener or click to enter the SLB instance, on the monitoring page, click Add listener.
- Complete the following operations to configure the listening protocol, then click Next.
Parameter | Description |
---|---|
Select Listener Protocol | Select a listening protocol. HTTP is selected in this example. |
Backend Protocol | In this topic, HTTP is used, and Backend Protocol is set to HTTP . |
Listening Port | Set the listening port that is used to receive requests and forward them to backend servers. Valid values: 1 to 65535. Port 80 is used for HTTP requests. |
Listener Name | Specify a name for the listener. The name must be 1 to 256 characters in length and can contain letters, digits, hyphens (-), forward slashes (/), periods (.), and underscores (_). |
Advanced | You can click Modify to configure the 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. If session persistence is enabled, CLB forwards all requests from a client to the same backend server. CLB persists HTTP sessions based on cookies. Cookie Persistence · Insert cookie : If you select this option, you need to only 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 carries this cookie, and the listener will forward this request to the recorded backend server. Persistent Timeout : If you select Insert cookie , you must specify the timeout period for session persistence. Valid values: 1 to 86400. Unit: seconds. · 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. Cookie Name : If you select Rewrite cookie, you must specify a name for the cookie. The name can contain letters, digits, underscores (_), and hyphens (-). |
Enable Access Control | Specify whether to enable access control. Select an access control method after you enable access control. Then, select a network access control list (ACL) 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. |
Enable Peak Bandwidth Limit | Specify whether to set the maximum bandwidth of the listener. Unit: Mbit/s. Valid values: 0 to 5120. If a pay-by-bandwidth CLB instance is used, you can set the maximum bandwidth of each listener to limit the amount of network traffic forwarded by listeners. The sum of the maximum bandwidth of all listeners that are added to a CLB instance cannot exceed the maximum bandwidth of the CLB instance. By default, this feature is disabled and all listeners share the bandwidth of the CLB instance. Note If a pay-by-data-transfer CLB instance is used, the bandwidth of its listeners is not limited by default. |
Idle Timeout | 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. When another request is received, CLB establishes a new connection. |
Request Timeout | Specify the request timeout period. Unit: seconds. Valid values: 1 to 180. If no response is received from a backend server within the specified timeout period, CLB returns the HTTP 504 error code 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 | Supported headers: · X-Forwarded-For: Add the header to retrieve client IP addresses. · SLB-ID: Add the header to retrieve the ID of the CLB instance. · SLB-IP: Add the header to retrieve the IP address of the CLB instance. · X-Forwarded-Proto: Add the header to retrieve the listening protocol. · X-Forwarded-Port: Add the header to retrieve the listening port. · X-Forwarded-Client- srcport : Add the header to retrieve client ports. |
Obtain Client Source IP Address | Specify whether to retrieve client IP addresses. 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 for the listener. |
3. 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 SLB instance, or create a vServer group or a primary/secondary server group.
- On the Backend Servers wizard page, select Default Server Group and 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 Port s and Weight s wizard page, specify the weights of the backend servers that you want to add. A backend server with a higher weight receives more requests.
- Click Add. On the Default Server Group tab, specify the ports that you want to open on the backend servers to receive requests. The backend servers are the ECS instances that you selected. Valid values: 1 to 65535. You can specify the same port on different backend servers that are added to an SLB instance.
- Click Next.
- 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. - Submit the configurations.
- HTTP listener configuration complete.