tencent cloud

Feedback

Getting Started with Domain Name-Based CLB

Last updated: 2024-01-04 09:44:16
    Tencent Cloud Cloud Load Balancer (CLB) supports various protocols such as TCP, UDP, TCP SSL, QUIC, HTTP, and HTTPS, providing businesses with both domain name- and URL-based forwarding services. This document describes how to quickly create a domain name-based CLB instance to forward client requests to two cloud virtual machine (CVM) instances.

    Prerequisites

    1. You have created two CVM instances. This document takes rs-1 and rs-2 as two sample instances. For information about how to create CVM instances, see Creating Instances via CVM Purchase Page.
    2. You have deployed real servers on the two CVM instances. This document takes HTTP forwarding as an example. Nginx servers have been deployed on CVM instances rs-1 and rs-2, and the two instances return two HTML static pages saying "Hello nginx! This is rs-1!" and "Hello nginx! This is rs-2!". For more information, see Deploying Nginx on CentOS.
    Note:
    This document describes the steps for bill-by-IP accounts. For bill-by-CVM accounts, first purchase public network bandwidth for CVM instances. If you are unsure of your account type, see Checking Account Type. In this example, different services deployed on real servers will return different values. In practice, the services deployed on real servers are identical, to provide a consistent experience for all users.

    Directions Overview

    Directions

    Step 1: Register a domain name

    Domain name registration is the prerequisite for building a service on the Internet.
    If you have already registered a domain name with another registrar, you can transfer it to Tencent Cloud domain service. For more information, see Domain Transfer In.
    If you do not have a domain name, you must register a domain name first.

    Step 2: Purchase a CLB instance

    After you purchase a CLB instance, the sytem automatically allocates a domain name to the instance. You can use this domain name to access the CLB service.
    1. Log in to the Tencent Cloud console and go to the CLB purchase page.
    2. On the CLB purchase page, select the region in which your CVM instances are located, and select CLB as the instance type and Public Network as the network type. For more information, see Product Attribute Selection.
    3. Click Buy now and complete the payment.
    4. Return to the Instance management page and select the region to view the newly created instance.

    Step 3: Configure a CLB listener

    CLB listeners implement forwarding based on the designated protocol and port. This document takes configuring a CLB listener to forward HTTP requests from clients as an example. For more information about CLB listeners, see CLB Listener Overview.

    Configure the HTTP listening protocol and port

    When a client initiates a request, the CLB instance will receive the request according to the listening frontend protocol and port, and forward the request to the real server.
    1. Log in to the CLB Console.
    2. On the Instance management page, click Configure listener in the Operation column of the target CLB instance.
    3. On the Listener Management tab, click Create in the HTTP/HTTPS Listener section.
    
    4. In the Create Listener pop-up window, configure the following parameters and click Submit. Listener name: The name can contain up to 60 characters, including letters, digits, hyphens (-), underscores (_), and dots(.). Listener protocol port: For example, enter HTTP:80.

    Configure a forwarding rule for the listener.

    If a client initiates a request, the CLB instance will forward the request according to the configured forwarding rule of the listener.
    1. On the Listener Management tab, locate the listener you created, and click on the right of the listener to add a rule.
    
    2. In the Create Forwarding Rules window, configure the domain name, URL, balancing method, and then click Next.
    Domain Name: The domain name of your real server, for example, www.example.com.
    Default Domain Name: If a client request does not match any listener domain names, the CLB instance will forward the request to the default domain name (default server). Each listener can be configured with only one default domain name. If a listener has no default domain name, the CLB instance will forward the request to the first domain name. In this example, the default domain name is not configured.
    URL: The access path to your real server, for example, /image/.
    Balance Method: Select Weighted Round Robin. For more information about balancing methods, see Load Balancing Methods.
    
    3. On the Health Check tab, enable Health Check, retain the default values for the Check Domain and Path fields, and click Next.
    
    4. Disable session persistence and click Submit.
    Note:
    Forwarding rules: Each listener can be configured with multiple domain names, and each domain name can be configured with multiple URLs. You can select a listener or domain name, and then click the + icon to create new rules.
    Session persistence: If session persistence is disabled and the round-robin balancing method is selected, requests from the same client will be assigned to different real servers in sequence; if session persistence is enabled, or session persistence is disabled but the ip_hash balancing method is selected, requests from the same client will always be assigned to the same real server.

    Bind real servers to the listener

    If a client initiates a request, the CLB instance will forward the request to the CVM instance that is bound to its listener for processing.
    1. On the Listener Management tab, click + on the left of the listener you created to display the listener information. Select the URL, and click Bind in the Forwarding Rules section on the right.
    
    
    
    
    2. In the pop-up window, select CVM as the instance type, select the two CVM instances rs-1 and rs-2 that are located in the same region as the CLB instance, set their ports to 80 and weights to 10 (the default value), and then click Confirm.
    
    3. Now you can view the bound CVM instances and their health check status in the Forwarding Rules section. If the port health status is Healthy, the CVM instances can normally process requests forwarded by the CLB instance.
    Note:
    One forwarding rule (containing the listening protocol, port, domain name, and URL) can be bound with multiple ports of the same CVM instance. If the same service is deployed on ports 80 and 81 of rs-1, both ports can be bound with the sample forwarding rule and both will receive requests forwarded by the CLB instance.

    Step 4: Configure a security group

    After creating a CLB instance, you can configure a security group to isolate public network traffic. For more information, see Configuring CLB Security Group. After configuring a security group, you can enable or disable the Allow by Default feature:

    Method 1: Enable "Allow by Default” for the security group

    For more information, see Configure Allow by Default.

    Method 2: Allow specific client IPs on the CVM security group

    For more information, see Configure Allow by Default.

    Step 5: Add a CNAME record

    After registering a domain name, you can add a CNAME record for the domain name so that the domain name can be used to access your website.
    1. Log in to the DNSPod console. On the domain name list page, click DNS in the Operation column of the target domain name.
    2. On the Record Management tab, click Add Record.
    
    
    3. In the Add Record section, set the following parameters:
    3.1 Host: specifies the prefix of the domain name. Valid values:
    www: The domain name is resolved to www.example.com.
    @: The domain name is resolved to example.com.
    *: matches all domain names in the format of *.example.com.
    3.2 Record Type: We recommend that you select CNAME.
    
    
    3.3 Split Zone: specifies the lines through which users access the domain name. If the host service provider provides only one IP address or domain name, you can select Default. Common line types are as follows: Default: The default line must be added. Otherwise, your website can be accessed only from specified lines. If your website can be accessed from two lines, we recommend you select China Telecom as the default line. China Unicom: specifies the server IP address for China Unicom users. Other users still access the domain name by using the default line. Search Engines: specifies a server IP address for web crawlers to fetch information from the website.
    3.4 Record Value: You can enter the domain name allocated by CLB.
    3.5 Retain the default values for other parameters and click Save.
    
    
    4. After adding the record, you can view the record in the record list on the Record Management tab.
    
    

    Step 6: Verify the CLB service

    After adding the record, wait for about 10 minutes and enter the bound CNAME domain name in the address bar of your browser. In this example, enter www.example.com. If the page appears normally, the CLB service is valid.

    Configuring Redirection (optional)

    CLB supports automatic redirection and manual redirection. For more information, see Layer-7 Redirection Configuration. Automatic redirection (forced HTTPS): When a PC or mobile browser accesses a web service with an HTTP request, an HTTPS response is returned to the browser after the request passes through the CLB proxy, forcing the browser to access the webpage by using HTTPS.
    Manual redirection: If you want to temporarily deactivate your web page in case of product sellout, page maintenance, or update and upgrade, you need to redirect the original page to a new page. Otherwise, a 404 or 503 error message page is returned when a user visits the original page. This results in compromised user experience and a waste of the access traffic, and may even invalidate the accumulated scores of the page on search engines.

    References

    Deploying Java Web on CentOS Install and Configure PHP
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support