You can associate a Server Load Balancer (SLB) instance with the instances of multiple applications to save costs. These applications share a public IP address and port. You can configure forwarding policies to forward requests to the applications. This topic describes how to configure domain names to forward traffic for multiple applications whose instances are associated with the same SLB instance and share the same port.

Background information

Note You can configure only HTTP listeners to forward traffic in Elastic Compute Service (ECS) clusters for applications that share the same port.

SLB instances support the HTTP protocol and can forward traffic based on the domain names and URLs in HTTP requests. In the following figure, the IP address of the SLB instance is mapped to the following domain names that are associated with the vServer groups of App1 and App2: abc***.com and xyz***.com. After the SLB instance receives HTTP requests, the SLB instance forwards traffic based on the domain names in the HTTP requests. The SLB instance forwards traffic to vServer Group A of App1 if the domain name is abc***.com and to vServer Group B of App2 if the domain name is xyz***.com.

JJHKH

For example, you have two applications. One is the User application that is used to query orders. The other is the Order application that is used for user logon. Both applications use the same public IP address and port. By default, port 80 is used. You can configure different domain names to forward traffic for the applications. In this example, u.domain.com is configured for the User application and o.domain.com is configured for the Order application.

Configure domain names to forward traffic

Procedure

The following procedure shows you how to associate an SLB instance with the instances of two different applications and configure different domain names to forward traffic:

  1. Create an SLB instance named edas-test-slb. For more information, see Create a CLB instance.
  2. Create an application that is deployed on an ECS cluster in the Enterprise Distributed Application Service (EDAS) console. Name the application spring-cloud-provider. Associate edas-test-slb with the instances of spring-cloud-provider. Set the listening protocol to HTTP and the port number to 80. Name the forwarding rule provider.test.com.
  3. Associate edas-test-slb with the instances of spring-cloud-consumer. The associating process is similar to that of associating edas-test-slb with the instances of spring-cloud-provider. The only difference is that the forwarding rule you create for spring-cloud-consumer is named consumer.test.com.

After you associate edas-test-slb with the instances of spring-cloud-provider and spring-cloud-consumer, you can add the following entries to the /etc/hosts file on your Linux or macOS client if the IP address of the SLB instance is 123.1.XX.XX.

123.1.XX.XX provider.test.com
123.1.XX.XX consumer.test.com

Then, you can use http://provider.test.com to access spring-cloud-provider and http://consumer.test.com to access spring-cloud-consumer.

Associate the SLB instance with the instances of the first application and configure a domain name-based forwarding policy

Associate the SLB instance with the instances of the first application, and configure a listening port, vServer group, and domain name-based forwarding policy.

  1. Log on to the EDAS console. In the left-side navigation pane, choose Application Management > Applications.
  2. On the Applications page, select a region in the top navigation bar and an option from the Microservice Namespace drop-down list. Select ECS Clusters from the Cluster Type drop-down list. Then, click the name of the required application in the application list.
  3. 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.
  4. In the AddLoad Balancing(Public) wizard, configure the SLB instance.
    1. In the Select SLB Instance step, set the SLBType parameter to ALB or CLB. Select the SLB instance that you have created from the SLB (Internet) drop-down list and click Next.
    2. In the Select and Configure Listener step, configure a listening port, and then click Next.

      If you set the SLBType parameter to ALB, you can select only an existing listening port. If you set the SLBType parameter to CLB, the following two options are available:

      • If you want to use an existing listening port that has been configured for the specified SLB instance, select Select Existing Listening Port and then select the listening port.
      • If no listening port is configured for the specified SLB instance or you want to add a listening port for the application, select Add Listening Port and then create a listener.

        Parameters

        Parameter Description
        Protocol Select HTTP. For more information about how to create an HTTP listener, see Add an HTTP listener for an Application Load Balancer (ALB) instance or Add an HTTP listener for a Classic Load Balancer (CLB) instance.
        Note A listener determines how SLB routes requests to backend servers. After you associate SLB instances with the instances of the applications that are hosted on ECS clusters in EDAS, you must configure listeners for the SLB instances. HTTP is applicable to applications that need to identify data content, such as web applications and small mobile games.
        Frontend Port Number The number of the port that is used by the SLB instance to provide external services.
        Important 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 remove 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. The default value is /_ehc.html. Enter a valid URI. For more information, see Configure and manage health checks.
        Backend Port Number The port number of the application. The value is fixed.
    3. In the Configure vServer Group and Forwarding Policy step, configure a vServer group for the SLB instance, configure a domain name-based forwarding policy, and then click Next.
      Parameter Description
      Default Server Group The default server group does not support forwarding policies. Therefore, you cannot select the default server group if you use a domain name to forward traffic. You must select a vServer group.
      Existing VServer Group If you want to use an existing vServer group that has been created for the specified SLB instance, perform the following steps:
      1. Select Existing VServer Group and then select an existing vServer group.
      2. Configure a forwarding rule.
        • To use an existing forwarding policy that has been configured for the vServer group, select Modify the forwarding policy of the current VServer group and then select the 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.
      Create VServer Group 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 step, check the SLB instance settings, and click Confirm.
  5. Check whether you can access the application by using the configured domain name-based forwarding policy. For more information, see Verification.

Associate the SLB instance with the instances of the second application and configure a domain name-based forwarding policy

Log on to the EDAS console. On the Applications page, click the name of the second application. In the Application Settings section of the Basic Information tab, repeat the operations described in the Associate the SLB instance with the instances of the first application and configure a domain name-based forwarding policy section of this topic. The SLB instance that you associate with and the listening port that you set for the second application are the same as those for the first application. The only differences are the vServer group and the domain name-based forwarding policy.