Classic Load Balancer (CLB) supports domain-based and URL-based forwarding rules. You can forward requests from the same domain name but different URLs to separate backend servers. This allows you to optimize load balancing among your server resources.

Background information

Note You can configure forwarding rules only for Layer 7 listeners that use HTTPS or HTTP.

This topic uses four Elastic Compute Services (ECS) instances that are deployed with NGINX servers to demonstrate how to configure domain-based and URL-based forwarding rules. The following table lists the forwarding requirements.

Frontend request Forwarded to
www.example.com/tom Backend servers SLB_tom1 and SLB_tom2, which belong to the vServer group TOM.
www.example.com/jerry The backend servers SLB_jerry1 and SLB_jerry2 belong to the vServer group JERRY.

Prerequisites

  1. An Internet-facing CLB instance is created. For more information, see Create a CLB instance.
  2. A Layer 7 listener is created. Round Robin (RR) is selected as the scheduling algorithm. For more information, see Add an HTTP listener or Add an HTTPS listener.
  3. Two vServer groups, TOM and JERRY, are created. For more information, see Create a vServer group.
    • Servers SLB_tom1 and SLB_tom2 are added to the vServer group TOM. The port is set to 80 and the default weight value 100 is used.
    • Servers SLB_jerry1 and SLB_jerry2 are added to the vServer group JERRY. The port is set to 80 and the default weight value 100 is used.

Configure forwarding rules

Perform the following operations:

  1. In the top navigation bar, select the region where the CLB instance is deployed.
  2. On the Instances page, click the ID of the CLB instance.
  3. On the Listener tab, find the Layer 7 listener that you want to manage and click Set Forwarding Rule in the Actions column.
  4. Configure two forwarding rules: forward requests from www.example.com/tom to the vServer group TOM and requests from www.example.com/jerry to the vServer group JERRY.

    Configure the following parameters:

    • 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, and the following special characters: -./%?#&.
      Note If you only want to configure only a domain-based forwarding rule, leave URL empty.
    • VServer Group: Select the vServer group that you want to associate with the forwarding rule.
    • Description: Enter a description.
    Note For more information about the maximum number of forwarding rules that can be configured for an HTTP or HTTPS listener, see Limits.
  5. Click Add Forwarding Rule and click OK.
  6. Check whether the forwarding rules work as expected.
    • Enter www.example.com/jerry in the browser and the following result will be returned:This is Jerry2!.
    • Enter www.example.com/tom in the browser and the following result will be returned:This is Tom1..
    • Enter www.example.com in the browser and the following result will be returned:Welcome to nginx!.