You can use OSS and Alibaba Cloud Content Delivery Network (CDN) together to accelerate downloads of static objects. These static objects are frequently downloaded by a large number of users in the same region at the same time. You can configure your OSS bucket as the origin server and use CDN to publish the data in the bucket to edge nodes. When a large number of end users must access an object in your bucket repeatedly, they can obtain the object cached in edge nodes to improve the response speed.

Prerequisites

A custom domain name is bound to the bucket. For more information, see Bind custom domain names.

Background information

To activate Alibaba Cloud CDN, you must map your custom domain name to an accelerated domain name. All requests destined for your custom domain name are forwarded to the edge nodes.
Notice
  • For other scenarios such as upload acceleration, we recommend that you use the transfer acceleration function provided by OSS. For more information, see Transfer acceleration.
  • After Alibaba Cloud CDN is activated, you are charged when you access OSS data by using accelerated domain names. For more information, see Basic service billing.
  • If the CDN cache does not contain the requested information when you access OSS data by using an accelerated domain name, the request is redirected to OSS. In this case, you are charged for CDN back-to-origin traffic and requests. For more information, see Billing items and methods.

Step 1: Bind an accelerated domain name

  1. Log on to the OSS console.
  2. Click the target bucket. Open the Domain Names tab.
    • New console
      1. Click Buckets, and then click the name of the target bucket.
      2. Choose Transmission > Domain Names.
    • Old console
      1. In the left-side navigation pane, click the name of the target bucket.
      2. On the Overview page of the bucket, click the Domain Names tab.
  3. In the list of domain names, click Not Configured in the Alibaba Cloud CDN column corresponding to the domain name that is to be bound. The CDN console appears.
  4. In the left-side navigation pane, click Domain Names. On the Domain Names page that appears, click Add Domain Name. In the Add Domain Name dialog box that appears, configure parameters listed in the following table.
    Parameter Description
    Domain Name The value is automatically set to the custom domain name that is bound to the bucket. Do not modify the value.
    Resource Groups Select Default Resource Group.
    Business Type Content delivery varies by business type. Select the appropriate business type based on your stored content and usage.
    Origin Info Click OSS Domain. Select an OSS domain name for which you want to accelerate the content delivery.
    Port Select an access port as needed.
    Region Select the region for which to accelerate your business.
  5. Click Next.
    After you add an accelerated domain name, a CNAME is generated. You must add the CNAME to the DNS of your DNS provider to enable CDN.

Step 2: Add a CNAME record

You must add a CNAME record to the DNS of your DNS provider. In this topic, Alibaba Cloud DNS is used as an example to describe the process of adding a CNAME record.

  1. Log on to the CDN console.
  2. In the left-side navigation pane, click Domain Names. Copy the CNAME corresponding to the domain name to which you want to add a record.
  3. Log on to the Alibaba Cloud DNS console.
  4. On the Manage DNS page that appears, click Configure in the Actions column corresponding to a domain name.
  5. On the DNS Settings tab that appears, click Add Record. In the Add Record dialog box that appears, configure parameters listed in the following table.
    Parameter Description
    Type Select the type of the record to direct requests.

    In this example, select CNAME.

    Host Enter the host record based on the prefix of the domain name. Examples:
    • If the domain name is www.aliyun.com, enter www.
    • If the domain name is aliyun.com, enter @.
    • If the domain name is abc.aliyun.com, enter abc.
    • If the domain is a second-level domain such as a.aliyun.com or b.aliyun.com, enter an asterisk (*).
    ISP Line Select the ISP line used to resolve the domain name.

    We recommend that you select Default to allow the system to select the optimal line.

    Value Enter the value of the record based on the selected record type.

    Enter the CNAME that was copied in Step 2.

    TTL Select the update period of the record. In this example, select the default value.
  6. Click OK.
    Note
    • A new CNAME record takes effect immediately. A modified CNAME record requires up to 72 hours to take effect.
    • It takes about 10 minutes until the CNAME status is updated. Therefore, even if you have configured a CNAME record, the You must add the CNAME record. message may be displayed on the Domain Names tab in the Alibaba Cloud CDN console. In this case, you can ignore the message.

Step 3: Enable auto CDN cache update

  1. Log on to the OSS console.
  2. Click the target bucket. Open the Domain Names tab.
    • New console
      1. Click Buckets, and then click the name of the target bucket.
      2. Choose Transmission > Domain Names.
    • Old console
      1. In the left-side navigation pane, click the name of the target bucket.
      2. On the Overview page of the bucket, click the Domain Names tab.
  3. In the list of custom domain names, you can turn on Auto CDN Cache Update for a domain name.
If an object is updated after the preceding operations are completed, OSS updates the updated object cached on CDN edge nodes. This way, objects cached on CDN edge nodes can be updated in real time.
Note After you unbind a custom domain name from a bucket, you cannot configure auto CDN cache update in the OSS console. Instead, you must configure this feature in the Alibaba Cloud CDN console.

AccessDenied is returned when you access a website

After you bind a custom domain name, you can add the specific path to the custom domain name to access OSS resources. Example: http://mydomain.cn/test/1.jpg. If you directly access a custom domain name such as http://mydomain.cn, AccessDenied is returned.

What to do next

  • To use an accelerated domain name to access OSS resources over HTTPS, you must host your certificate in OSS. For more information, see Upload an SSL certificate.
  • If Alibaba Cloud CDN is enabled, you must configure CORS rules in the CDN console to implement cross-origin access. For more information, see Configure CORS for Alibaba Cloud CDN.