All Products
Search
Document Center

Server Load Balancer:Forward requests destined for the same domain name but different URLs

Last Updated:Nov 13, 2023

Classic Load Balancer (CLB) supports domain name-based and URL-based forwarding rules. You can configure forwarding rules to forward requests destined for the same domain name but different URLs to different vServer groups. 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 on which NGINX servers are deployed to demonstrate how to configure domain name-based and URL-based forwarding rules. The following table describes the forwarding rules.

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

Backend servers SLB_jerry1 and SLB_jerry2, which belong to the vServer group JERRY.

Prerequisites

  1. An Internet-facing CLB instance is created. For more information, see Create and manage 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 and manage 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 steps:

  1. In the top navigation bar, select the region in which the CLB instance is deployed.

  2. On the Instances page, find the CLB instance that you want to manage and click its ID.

  3. On the Listeners 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 to forward requests destined for www.example.com/tom to the vServer group TOM and requests destined for www.example.com/jerry to the vServer group JERRY.

    The following table describes the parameters.

    Domain Name

    URL

    vServer Group

    www.example.com

    /tom

    TOM

    /jerry

    JERRY

    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 Policy.

  6. Check whether the forwarding rules work as expected.

    • Visit www.example.com/jerrry in a browser. If This is Jerry1. or This is Jerry2. is returned, the forwarding rule for www.example.com/jerrry works as expected.

    • Visit www.example.com/tom in a browser. If This is Tom1. or This is Tom2. is returned, the forwarding rule for www.example.com/tom works as expected.