You can use Alibaba Cloud CDN to accelerate the retrieval of static resources from an Object Storage Service (OSS) bucket. This topic describes how to accelerate the retrieval of resources from an OSS bucket in the Alibaba Cloud CDN console and the use scenarios of Alibaba Cloud CDN.

Prerequisites

Background information

Static resources stored in OSS buckets include static scripts, images, attachments, audio files, and video files. CDN edge nodes cache static resources from an OSS bucket. When a client requests the cached static resources, the scheduling system redirects the request to the CDN edge node that is nearest to the client. Then, the CDN edge node returns the cached resources to the client. The following figure shows how Alibaba Cloud CDN accelerates the retrieval of resources from an OSS bucket. Use scenario
In the preceding figure, the OSS bucket is specified as the origin server. The retrieval of content stored in the OSS bucket is accelerated by Alibaba Cloud CDN. Visitors retrieve files from the nearest CDN edge nodes. This architecture provides the following benefits:
  • All requests destined for the origin server are redirected to CDN edge nodes. This reduces loads on the origin server.
  • You are charged for outbound data transfer to Alibaba Cloud CDN instead of outbound data transfer to the Internet. Outbound data transfer to Alibaba Cloud CDN is billed at a lower price.
  • Clients retrieve static resources from the nearest CDN edge nodes. This minimizes the network transmission distance and ensures the quality of data transmission.

Procedure

  1. In the Alibaba Cloud CDN console, add the OSS bucket as the origin server.
    1. Log on to the Alibaba Cloud CDN console.
    2. In the left-side navigation pane, click Domain Names.
    3. On the Domain Names page, click Add Domain Name.
    4. On the Add Domain Name page, set the following parameters.

      Step 1: Set the basic information about the origin server

      intl
      Parameter Description
      Domain Name to Accelerate
      Take note of the following rules:
      • The domain name to be accelerated can be a specific name or a wildcard domain name. The domain name must be in lowercase letters. Chinese characters are not supported.

        If the domain name is example.com, the domain name to be accelerated can be a lower-level domain name of example.com, for example, cdntest.example.com.

      • You can specify a wildcard domain name, such as *.example.com. For more information about the rules for adding wildcard domain names, see Rules for adding wildcard domain names.
        Note
        • The specified wildcard domain name and the domain names that match the wildcard domain name must belong to the same Alibaba Cloud account. When you add a domain name to Alibaba Cloud CDN, Alibaba Cloud CDN verifies the ownership of the domain name. If the specified wildcard domain name and the domain names that match the wildcard domain name belong to different Alibaba Cloud accounts, an error message appears. To request technical support from Alibaba Cloud, submit a ticket.
        • If a wildcard domain name is not added to Alibaba Cloud CDN, you can add domain names that match the wildcard domain name to Alibaba Cloud CDN by using different Alibaba Cloud accounts.
      • You cannot add duplicate domain names to Alibaba Cloud CDN.

        If the system prompts that the domain name has been added to other Alibaba Cloud services such as ApsaraVideo VOD, ApsaraVideo Live, or Dynamic Route for CDN (DCDN), you can submit a ticket.

      • Each Alibaba Cloud account can add at most 50 domain names to Alibaba Cloud CDN.

        However, if the sum of the average daily peak bandwidth values of your domain names exceeds 50 Mbit/s, you can submit a ticket to add more domain names to Alibaba Cloud CDN. Make sure that the increase of domain names does not cause business risks.

      • The content delivered from the domain name must be legal and comply with the Terms of Service for Alibaba Cloud CDN. For more information, see Limits.
      Business Type
      Business Type cannot be modified after it is set.
      • Image and small file distribution: accelerates the delivery of small-sized static content on websites, such as e-commerce content and game images.
      • Large file distribution: accelerates the delivery of static files that are larger than 20 MB.
      • On-demand audio and video streaming: accelerates the delivery of audio or video content.
      • What is DCDN?: accelerates the delivery of both static and dynamic content. DCDN can accelerate the delivery of large amounts of dynamic content.

        If you set Business Type to DCDN, you must follow the instructions to go to the DCDN console to add and configure the domain name. For more information, see Add a domain name.

      Region
      Select an accelerated region. If you select Mainland China Only or Global, you must apply for an ICP number for the accelerated domain name. We recommend that you use Alibaba Cloud ICP Filing System to apply for ICP numbers. It may take some time for Ministry of Industry and Information Technology (MIIT) to update data in the database. After you submit domain name information to MIIT, we recommend that you wait 8 hours before you configure the domain name in Alibaba Cloud CDN.
      Note The pricing strategies vary based on the accelerated region. Choose an accelerated region based on your business requirements. For more information about the pricing of Alibaba Cloud CDN, see CDN Pricing.
      • Mainland China Only: All requests are scheduled to edge nodes that are deployed in mainland China. Requests from outside mainland China are scheduled to edge nodes managed by China Telecom (East China Division).
      • Global: All requests are scheduled to the nearest edge nodes.
      • Global (Excluding Mainland China): All requests are scheduled to edge nodes that are deployed in Hong Kong (China), Macao (China), Taiwan (China), or other countries or regions outside mainland China. However, requests from mainland China are scheduled to edge nodes that are deployed in Japan, Singapore, or Hong Kong (China).
      Step 2: Configure the origin serverOrigin Info
      Parameter Description
      Origin Info Select OSS Domain and select the domain name of the selected OSS bucket. For more information about how to map an OSS bucket to a custom domain name, see Map custom domain names.
      Priority

      You can set priorities to specify primary and secondary origin servers. The primary origin server has a higher priority than the secondary origin servers. Alibaba Cloud CDN preferably redirects requests to the primary origin server.

      For example, you have specified two origin servers: Server A and Server B. Server A is the primary origin server and Server B is the secondary origin server. In this case, Alibaba Cloud CDN preferably redirects requests to Server A. If Origin Server A fails, Alibaba Cloud CDN redirects user requests to Origin Server B. After Origin Server A recovers, Alibaba Cloud CDN fails back to Origin Server A.

      Weight

      If origin servers have the same priority, Alibaba Cloud CDN redirects requests to the origin servers based on their weights. This balances loads among the origin servers. The valid values of origin server weights are 1 to 100. A greater value indicates a higher weight. An origin server with a higher weight receives more user requests. The default weight is 10. You can specify a weight based on your business requirements.

      For example, both Origin Server A and Origin Server B are specified as primary origin servers. The weight of Origin Server A is 80 and the weight of Origin Server B is 20. In this case, Alibaba Cloud CDN redirects user requests to both origin servers at a ratio of 8:2.

      Port
      The default port is port 80. You can specify a port based on the settings of your origin server. Valid values are 1 to 65535.
      • If you specify port 443, requests are redirected to the origin server over HTTPS.
      • If you specify port 80 or a custom port, requests are redirected to the origin server over HTTP. If you want Alibaba Cloud CDN to redirect HTTPS requests to origin servers over custom ports, submit a ticket.
        Note
        • If Origin Protocol Policy is enabled, custom ports cannot take effect. For more information about how to disable the origin protocol policy, see Configure the origin protocol policy.
        • If the origin server is an OSS bucket, OSS determines whether you can specify a custom port.
    5. Optional. Click Next.
      If this is the first time the domain name is added to Alibaba Cloud CDN, Alibaba Cloud CDN must verify the ownership of the domain name. If the domain name has already passed the verification, skip this step. For more information, see Verify the ownership of a domain name.
    6. Wait for manual review.
      Note If the domain name does not need to be manually verified, proceed to the next step. In the next step, you can set the parameters based on your business requirements.

      It takes one to two business days to verify the ownership of a domain name. If the origin server is an ECS instance or an OSS bucket, you can submit a ticket. It takes less time to verify the ownership of an ECS instance or an OSS bucket.

      After the domain name passes the verification, you can check the status of the domain name on the Domain Names page. If the domain name is in the Enabled state, it indicates that the domain name is added to Alibaba Cloud CDN.

  2. On the Domain Names page, copy the CNAME of the domain name to be accelerated.
    Domain Names
  3. In the Alibaba Cloud DNS console, add a CNAME record for the domain name.
    In the following example, Alibaba Cloud DNS is used to demonstrate how to configure a CNAME record.
    1. Log on to the Alibaba Cloud DNS console with the Alibaba Cloud account to which the domain name belongs.
    2. On the Manage DNS page, find the domain name that you want to manage and click Configure in the Actions column.
      Note If the domain name is not registered through Alibaba Cloud Domains, you must add the domain name to Alibaba Cloud DNS before you can add a DNS record for it. For more information, see Domain management.
    3. Click Add Record and add a CNAME record.
      Note
      • The CNAME record of a specific domain name takes precedence over that of a wildcard domain name. If the domain name to be accelerated is a wildcard domain name, and the host record includes an asterisk (*), you must delete all effective DNS records of the second-level domain names that match the wildcard domain name.
      • If the CNAME record that you want to use conflicts with an existing DNS record, we recommend that you use another domain name or modify the existing DNS record.
      Add a CNAME record
      Parameter Description Example
      Type Select CNAME from the drop-down list. CNAME
      Host Enter the prefix of the domain name.
      • If the domain name to be accelerated is testcdn.aliyun.com, enter testcdn.
      • If the domain name to be accelerated is www.aliyun.com, enter www.
      • If the domain name to be accelerated is aliyun.com, enter @.
      • If the domain name to be accelerated is *.aliyun.com, enter *.
      ISP Line Enter the default Internet service provider (ISP) line. Keep the default setting.
      Value
      Enter the CNAME of the domain name.
      Note Each accelerated domain name is assigned a unique CNAME. Second-level domain names cannot use the CNAME of the top-level domain name. If you want to accelerate a second-level domain name, add the second-level domain name to Alibaba Cloud CDN. Alibaba Cloud then assigns a CNAME to the second-level domain name. Alternatively, you can add a second-level wildcard domain name to Alibaba Cloud CDN. Domain names that match the wildcard domain name are mapped to the CNAME of the wildcard domain name. For more information, see Add a domain name to Alibaba Cloud CDN.
      all.example.com.w.kunlunsl.com
      TTL Enter a time-to-live (TTL) value for the CNAME record. A smaller value indicates a shorter period of time to apply record updates. The default TTL value is 10 minutes. Keep the default setting.
    4. Click OK.
      After the CNAME record takes effect, acceleration is immediately enabled for the domain name. Newly added CNAME records take effect immediately. By default, it takes 10 minutes for a modified CNAME record to take effect because the default TTL value of a CNAME record is 10 minutes. The time period varies based on the TTL value that you specify for the CNAME record. After you add a CNAME record, it takes about 10 minutes for the system to update the status in the console. The system may prompt that you must add a CNAME record. Ignore the message.
  4. Use an on-premises machine to check whether the CNAME record takes effect.
    Method A: In the CNAME configuration guide, click Search to query the status of the CNAME record.
    Method B: Run the ping command to ping the domain name.
    1. Open Command Prompt in Windows.
    2. Run the ping command to ping the domain name. If the CNAME in the output is the same as the CNAME that is assigned to the domain name, it indicates that acceleration is enabled for the domain name.
      Check whether the CNAME record takes effect
  5. In the OSS console, turn on Auto CDN Cache Update for the domain name.
    Note After you turn on Auto CDN Cache Update, OSS automatically updates the objects cached on CDN edge nodes when the same objects in the OSS bucket are updated. This ensures that the objects cached on CDN edge nodes are up to date. After you remove the mapping between the domain name and the OSS bucket, you cannot enable Auto CDN Cache Update for the domain name in the OSS console. However, you can configure the refresh and prefetch features for the domain name in the Alibaba Cloud CDN console. For more information, see Refresh resources.
    1. Log on to the OSS console.
    2. In the left-side navigation pane, click Buckets.
    3. On the Buckets page, find the OSS bucket and click the bucket name.
    4. In the left-side navigation pane, choose Transmission > Domain Names.
    5. On the Domain Names tab, turn on Auto CDN Cache Update.
      Domain Names

What to do next

After the CNAME record takes effect, if a client retrieves resources stored in the OSS bucket by sending a request to the accelerated domain name, an AccessDenied error occurs. To resolve this problem, visitors can use one of the following methods to retrieve the resources:
  • Access resources in the OSS bucket from a web browser.

    Visitors can concatenate the accelerated domain name and file path, and then enter the concatenated URL into a web browser. For example, the accelerated domain name is aliyundoc.com and the file that the visitor wants to access is image_01.jpg, which is under the root directory. In this case, the visitor can enter the URL http://aliyundoc.com/image_01.jpg into the web browser.

  • Access resources in the OSS bucket from a client

    Visitors can set the domain name of the OSS bucket to the accelerated domain name in their clients. Then, the visitors can access resources in the OSS bucket through the accelerated domain name from their clients.