The Layer 7 listeners of Classic Load Balancer (CLB), including HTTPS listeners and HTTP listeners, support forwarding rules based on domain names or URLs. You can forward requests from different domain names or URLs to different backend server groups. This ensures that server resources are allocated in an optimized manner.
How it works
URL-based forwarding rules support string matching. Longest prefix matching is used. For example, if two forwarding rules /abc and /abcd are configured and a request contains the prefix /abcde, the request matches the /abcd rule.
- Exact domain name:
www.aliyun.com
. - Wildcard domain names:
*.aliyun.com
and*.market.aliyun.com
.If a request matches multiple domain name-based forwarding rules, exact matching prevails over wildcard pattern matching. If a request matches multiple wildcard domain names, a higher-level wildcard domain name prevails over a lower-level wildcard domain name.
Note "√" indicates that the domain name of the request matches the domain name specified in the forwarding rule. "×" indicates that the domain name of the request does not match the domain name specified in the forwarding rule.Mode Request URL Domain name-based forwarding rule www.aliyun.com *.aliyun.com *.market.aliyun.com Exact matching www.aliyun.com √ × × Wildcard pattern matching market.aliyun.com × √ × info.market.aliyun.com × × √
You can add multiple forwarding rules to a listener. Each forwarding rule is associated with a vServer group. A vServer group contains one or more Elastic Compute Service (ECS) instances. You can configure a listener to forward read requests to one vServer group and forward write requests to another vServer group. This allows you to optimize load balancing among your server resources.

- Model 1: If a request contains a domain name, the system matches the domain name of the request against domain-based forwarding rules.
- If the domain name of the request matches the domain name specified in a forwarding rule, the system continues to match the URL.
In this case, if the URL of the request matches the URL specified in a forwarding rule, the request is forwarded to the vServer group specified in this forwarding rule. If no forwarding rule matches the URL, the request is forwarded based on a root domain-based forwarding rule. Root domain-based forwarding rules contain only domain names. URLs are not specified in root domain-based forwarding rules.
If root domain-based forwarding rules are not configured for the domain name, the error message 404 is returned to the client.
- If no forwarding rule matches the domain name of the request, the request is forwarded in Model 2.
- If the domain name of the request matches the domain name specified in a forwarding rule, the system continues to match the URL.
- Model 2: If a request does not contain a domain name or no forwarding rule matches the domain name, the request is forwarded based on URL-based forwarding rules. URL-based forwarding rules contain only URLs. Domain names are not specified in URL-based forwarding rules.
In this case, if the URL of the request matches the URL specified in a URL-based forwarding rule, the request is forwarded to the vServer group specified in the forwarding rule. If no URL-based forwarding rule matches the URL, the request is forwarded to the server group that is configured for the listener.
Prerequisites
- A CLB instance is created and an HTTP or HTTPS listener is created for the CLB instance. For more information, see Add an HTTP listener or Add an HTTPS listener.
- vServer groups are created. For more information, see Create and manage a vServer group.
Configure domain name-based or URL-based forwarding rules
- Log on to the CLB console.
- Select the region to which the CLB instance that you want to manage belongs.
- On the Instances page, click the ID of the CLB instance.
- On the Listener tab, find the Layer 7 listener that you want to manage and click Set Forwarding Rule in the Actions column.
- In the Routing Method panel, set the following parameters and click Add Forwarding Rules.
- Domain Name: Enter the domain name from which requests are forwarded. The domain name can contain only letters, digits, hyphens (-), and periods (.).
- URL: Enter the URL from which requests are forwarded. The URL must start with a forward slash (/). The URL can contain only letters, digits, hyphens (-), periods (.), forward slashes (/), percent signs (%), question marks (?), number signs (#), and ampersands (&). Note If the URL of a request contains special characters, you must use URL escape codes to convert the special characters. For example, if the URL of a request contains a number sign (#), the number sign must be converted into the escape code (% 23). This way, the system can match the URL of the request against the URL-based forwarding rule.
- VServer Group: Select the vServer group that you want to associate with the forwarding rule.
- Description: Enter a description.
- Add Forwarding Rules: Select whether to add another forwarding rule.
- Optional:Click Add Domain to add a domain name-based forwarding rule, or click Add Rule to add a URL-based forwarding rule.
For more information about the maximum number of forwarding rules that can be configured for an HTTP or HTTPS listener, see Limits.
Modify forwarding rules
- Log on to the CLB console.
- Select the region to which the CLB instance that you want to manage belongs.
- On the Instances page, click the ID of the CLB instance.
- On the Listener tab, find the Layer 7 listener that you want to manage and click Set Forwarding Rule in the Actions column.
- In the Forwarding Rules section of the Routing Method panel, find the forwarding rule that you want to manage and click Edit in the Actions column.
- In the Edit Forwarding Rule panel, modify the description and change the vServer group.
- You can turn on Advanced Settings, set the following parameters, and then click OK.
Parameter Description Forwarding Rule 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 distributed to backend servers in sequence.
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 enables 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 to specify only the timeout period of the cookie.
CLB inserts a cookie (SERVERID) into the first HTTP or HTTPS response packet that is sent to a client. The next request from the client contains this cookie, and the listener distributes the request to the recorded backend server.
- Rewrite cookie: If you select this option, you can specify the cookie to be inserted into an HTTP or HTTPS response. In this case, you must specify the timeout period and 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. For more information, see Configure session persistence.
Enable Health Check - Health Check Method: The default value HEAD is used.
- Health Check Port: Specify the port that is used by health checks to access backend servers.
By default, the backend port specified in the listener configuration is probed.
- Health Check Path: Specify the URL that is used for health checks. We recommend that you perform health checks on static web pages.
- Health Check Domain Name (Optional): Specify the domain name that is used for health checks. By default, the private IP addresses of backend servers are converted into domain names that are used for health checks.
- Normal Status Code: Select the HTTP status code that indicates a successful health check.
By default, http_2xx and http_3xx are selected.
- Response Timeout: Specify the timeout period for a health check response. If a backend server does not respond within the specified timeout period, the backend server fails the health check.
- Health Check Interval: Specify the time interval between two consecutive health checks.
Default value: 2. Unit: seconds.
- Healthy Threshold: Specify the number of successful health checks that must be consecutively performed before an ECS instance is declared healthy.
Valid values: 2 to 10. Default value: 3.
- Unhealthy Threshold: Specify the number of failed health checks that must be consecutively performed before an ECS instance is declared unhealthy.
Valid values: 2 to 10. Default value: 3.
Delete a forwarding rule
- Log on to the CLB console.
- Select the region to which the CLB instance that you want to manage belongs.
- On the Instances page, click the ID of the CLB instance.
- On the Listener tab, find the Layer 7 listener that you want to manage and click Set Forwarding Rule in the Actions column.
- In the Forwarding Rules section of the Routing Method panel, find the forwarding rule that you want to delete and click Delete in the Actions column.
References
- CreateDomainExtension: adds an additional domain name.
- DescribeDomainExtensionAttribute: queries an additional domain name.
- SetDomainExtensionAttribute: replaces the certificate associated with an additional domain name.
- DescribeDomainExtensions: queries additional domain names.
- DeleteDomainExtension: deletes an additional domain name.