To reduce costs, you can use a shared Server Load Balancer (SLB) instance for multiple applications. The applications use the same public IP address and port. The requests from the Internet are forwarded to the applications based on specified forwarding policies. This topic describes how to use domain names to distribute traffic when multiple applications use the same SLB instance and port.

Prerequisites

An SLB instance is created. For more information, see Create an SLB instance.

Background information

Note You can configure only HTTP listeners in Elastic Compute Service (ECS) clusters to distribute traffic.

For example, you have the following two applications: the User application that is used to query orders and the Order application that is used for user logon. The applications use the same public IP address and port. Port 80 is used by default. To distribute traffic, you can configure different domain names for the applications. In this example, u.domain.com is used for the User application and o.domain.com is used for the Order application.

通过域名实现流量分发

Bind the SLB instance to the first application and configure a domain name-based forwarding policy

Bind the SLB instance to the first application, and configure a listening port, vServer group, and domain name-based forwarding policy.

  1. Log on to the EDAS console.
  2. In the left-side navigation pane, click Applications.
  3. On the Applications page, select a region in the top navigation bar and select a namespace from the Namespace drop-down list. From the Cluster Type drop-down list, select ECS Cluster. Then, click the name of the required application in the application list.
  4. In the Application Settings section of the Basic Information page, click Add next to SLB (Internet).
    Note If you have configured an SLB instance, the IP address and port number of the SLB instance are displayed. You can click Modify to go to the configuration page and modify the settings of the SLB instance. You can also click Unbind to unbind the SLB instance.
  5. Configure the SLB instance in the Bind SLB Instance to Application wizard.
    1. In the Select SLB step, select the SLB instance that you have created from the SLB (Internet) drop-down list, and then click Next.
      选择SLB实例
    2. In the Select and Configure Listener step, configure a listening port, and then click Next.
      • If you want to use the existing listening port that is configured for the specified SLB instance, select Select an Existing Listening Port and then select the required listening port.
      • If no listening port has been configured for the specified SLB instance or you want to add a listening port to the application, select Add Listening Port and then create a listener.

        Parameters

        Parameter Description
        Protocol TCP and HTTP are supported. Select a protocol as needed. For more information, see Listener overview.
        Frontend Port Number The number of the port that is used by the SLB instance to provide services.
        Notice If the port number that you want to add is used by another listening protocol, you must set another port number. You can also log on to the SLB console to delete the listening port, and then add the port in the EDAS console.
        Health Check Path (URI) The URI that is used by the SLB instance to check the status of the backend application. The default value is /_ehc.html. Enter a valid URI. For more information, see Configure health check.
        Backend Port Number The port number of the application. The value is fixed.
    3. In the Configure Virtual Groups and Forwarding Policies step, configure a vServer group for the SLB instance, configure a domain name-based forwarding policy, and then click Next.
      Note The default server group does not support configuring forwarding policies. Therefore, you cannot select the default server group if you use a domain name to distribute traffic. You must select a vServer group.

      You can use one of the following methods to configure a vServer group and domain name-based forwarding policy for the application:

      • If you want to use the vServer group that is created for the specified SLB instance, perform the following operations:
        1. Select Existing VServer Group and then select an existing vServer group.
          Notice A vServer group can be bound to only one application or application group.
        2. Configure a forwarding policy.
          • To use a forwarding policy that is configured for the vServer group, select Modify the forwarding policy of the current VServer group and then select the required forwarding policy.
          • If no forwarding policies have been configured for the vServer group or you want to add a forwarding policy, select Add Forwarding Policy and then specify a domain name in the Forwarding Policy field.
      • If no vServer group has been configured for the specified SLB instance or you want to add a vServer group for the application, perform the following steps:
        1. Select Create VServer Group and specify the VServer Group Name parameter.
        2. Select Add Forwarding Policy and then specify a domain name in the Forwarding Policy field.
    4. In the Confirm SLB Change step, view the specified SLB instance information. Then, click Confirm.
  6. Check whether you can access the first application by using the configured domain name-based forwarding policy. For more information, see Verify the result.

Bind the SLB instance to the second application and configure a domain name-based forwarding policy

Bind the SLB instance to the second application. When you configure the SLB instance, use the port number that is specified for the first application. Configure a vServer group and domain name-based forwarding policy that are not used by the first application.

  1. Log on to the EDAS console.
  2. In the left-side navigation pane, click Applications.
  3. On the Applications page, select a region in the top navigation bar and select a namespace from the Namespace drop-down list. From the Cluster Type drop-down list, select ECS Cluster. Then, click the name of the required application in the application list.
  4. In the Application Settings section of the Basic Information page, click Add next to SLB (Internet).
    Note If you have configured an SLB instance, the IP address and port number of the SLB instance are displayed. You can click Modify to go to the configuration page and modify the settings of the SLB instance. You can also click Unbind to unbind the SLB instance.
  5. Configure the SLB instance in the Bind SLB Instance to Application wizard.
    1. In the Select SLB step, select the SLB instance that you have created from the SLB (Internet) drop-down list, and then click Next.
      选择SLB实例
    2. In the Select and Configure Listener step, select Select an Existing Listening Port, select the same listening port as the first application, and then click Next.
      Select an existing listening port
    3. In the Configure Virtual Groups and Forwarding Policies step, configure a vServer group for the SLB instance, configure a domain name-based forwarding policy, and then click Next.
      Note The default server group does not support configuring forwarding policies. Therefore, you cannot select the default server group if you use a domain name to distribute traffic. You must select a vServer group.

      A vServer group can be bound to only one application or application group. Therefore, the specified vServer group cannot be the same as the vServer group that is bound to the first application. We recommend that you select Create vServer Group and Add Forwarding Policy.

      If you have created an SLB instance and configured a vServer group and forwarding policy in the SLB console, you can use the existing vServer group and forwarding policy. For more information, see 5.

      Add a vServer group and forwarding policy
    4. In the Confirm SLB Change step, view the specified SLB instance information. Then, click Confirm.
  6. Check whether you can access the first application by using the configured domain name-based forwarding policy. For more information, see Verify the result.