Updated on 2024-09-20 GMT+08:00

Forwarding Policy

Scenarios

You can add forwarding policies to HTTP or HTTPS listeners to forward requests to different backend server groups based on domain names or URLs.

This is suited for applications that are deployed on multiple backend servers and provide multiple types of services such as videos, images, audios, and texts.

A forwarding policy consists of a forwarding rule and an action.

  • There are two types of forwarding rules: domain name and URL.
  • HTTP listeners can forward requests to a backend server group and redirect requests to another listener.
  • HTTPS listeners can forward requests to a backend server group.

How Requests Are Matched

  • After you add a forwarding policy, the load balancer forwards requests based on the specified domain name or URL:
    • If the domain name or URL in a request matches what is specified in the forwarding policy, the request is forwarded to the backend server group you select or create when you add the forwarding policy.
    • If the domain name or URL in a request does not match what is specified in the forwarding policy, the request is forwarded to the default backend server group of the listener.
  • Matching priority:
    • Forwarding policy priorities are independent of each other regardless of domain names. If a forwarding rule uses both domain names and URLs, requests are matched based on domain names first.
    • If the forwarding rule is a URL, the priorities follow the order of exact match, prefix match, and regular expression match. If the matching types are the same, the longer the URL length, the higher the priority.
Table 1 Example forwarding policies

Request

Forwarding Policy

Forwarding Rule

Specified Value

www.elb.com/test

1

URL

/test

2

Domain name

www.elb.com

In this example, request www.elb.com/test matches both forwarding policies 1 and 2, but is routed based on forwarding policy 2.

Notes and Constraints

  • Forwarding policies can be added only to HTTP and HTTPS listeners.
  • Forwarding policies must be unique.
  • A maximum of 100 forwarding policies can be configured for a listener. If the number of forwarding policies exceeds the quota, the excess forwarding policies will not be applied.
  • When you add a forwarding policy, note the following:
    • You can specify a URL that does not contain query strings. If the URL is set to /path/resource?name=value, the forwarding policy will not be applied.
    • Each URL path must exist on the backend server. If the path does not exist, the backend server will return 404 Not Found.
    • In the regular expression match, the characters are matched sequentially, and matching ends when any rule is successfully matched. Matching rules cannot overlap with each other.
    • A URL path cannot be configured for two forwarding policies.
    • A domain name cannot exceed 100 characters.

If you add a forwarding policy that is the same as an existing one by calling APIs, there will be a conflict. Even if you delete the existing forwarding policy, the new forwarding policy is still faulty. Delete the newly-added forwarding policy and add a different one.

Adding a Forwarding Policy

  1. Go to the load balancer list page.
  2. On the displayed page, locate the load balancer you want to add forwarding policies to and click its name.
  3. On the Listeners tab, add a forwarding policy in either of the following ways:
    • On the Listeners page, locate the listener, and click Add/Edit Forwarding Policy in the Forwarding Policies column.
    • Locate the target listener, click its name, and click Forwarding Policies.
  4. Click Add Forwarding Policy. Configure the parameters based on Table 2.
  5. After the configuration is complete, click Save.
Table 2 Forwarding policy parameters

Parameter

Description

Example Value

Forwarding Rule

Domain name

Specifies the domain name used for forwarding requests. The domain name in the request must exactly match that in the forwarding policy.

You need to specify either a domain name or URL.

www.test.com

URL

  • Description

    Specifies the path used for forwarding requests. A URL can contain letters, digits, and special characters: _~';@^-%#$.*+?,=!:|\/()[]{}

  • Matching rules
    • Exact match: The request URL is the same as the specified URL and must start with a slash (/).
    • Prefix match: The requested URL starts with the specified URL string.
    • Regular expression match: The URLs are matched using a regular expression.

/login.php

Action

Forward to a backend server group

If the request matches the configured forwarding rule, the request is forwarded to the specified backend server group.

Forward to a backend server group

Redirect to another listener

If the request matches the configured forwarding rule, the request is redirected to the specified HTTPS listener.

This action can be configured only for HTTP listeners.

NOTE:

If you select Redirect to another listener and create a redirect for the current listener, this listener will redirect the requests to the specified HTTPS listener, but access control configured for the listener will still take effect.

For example, if you configure a redirect for an HTTP listener, HTTP requests to access a web page will be redirected to the HTTPS listener you select and handled by the backend servers associated with the HTTPS listener. As a result, the clients access the web page over HTTPS. The configuration of the HTTP listener will become invalid.

N/A

Backend Server Group

Select a backend server group that will receive requests from the load balancer.

This parameter is mandatory when you set Action to Forward to a backend server group.

N/A

Listener

Select an HTTPS listener that will receive requests redirected from the current HTTP listener.

This parameter is mandatory when Action is set to Redirect to another listener.

N/A

URL Matching Example

The following table lists how a URL is matched, and Figure 1 shows how a request is forwarded to a backend server group.

Table 3 URL matching

URL Matching Rule

URL

URL in the Forwarding Policy

N/A

N/A

/elb/index.html

/elb

/elb[^\s]*

/index.html

Exact match

/elb/index.html

-

-

-

Prefix match

-

-

Regular expression match

-

-

Figure 1 Request forwarding

In this figure, the system first searches for an exact match of the requested URL (/elb_gls/glossary.html). If there is no exact match, the system searches for a prefix match. If a match is found, the request is forwarded to backend server group 2 even if a regular expression match is also found, because the prefix match has a higher priority.

Modifying a Forwarding Policy

  1. Go to the load balancer list page.
  2. On the displayed page, locate the load balancer whose forwarding policies you want to modify and click its name.
  3. Click Listeners, locate the listener, and click its name.
  4. On the Forwarding Policies tab, select the forwarding policy, and click Edit.
  5. Modify the parameters and click Save.

Deleting a Forwarding Policy

  1. Go to the load balancer list page.
  2. On the displayed page, locate the load balancer whose forwarding policies you want to delete and click its name.
  3. Click Listeners, locate the listener, and click its name.
  4. On the Forwarding Policies tab, select the forwarding policy, and click Delete on the top right.
  5. In the displayed dialog box, click OK.