You can use Object Storage Service (OSS) together with Alibaba Cloud CDN to cache objects stored in OSS to Alibaba Cloud CDN points of presences (POPs). When a large number of users need to frequently access an object in your OSS bucket, the users can retrieve the object from CDN POPs. This shortens the response time.
Prerequisites
An Internet Content Provider (ICP) filing is obtained from the Ministry of Industry and Information Technology (MIIT) for the domain name that you want to map to your bucket if the bucket is located in the Chinese mainland. For more information, see What is an ICP filing?
Background information
When you use OSS together with Alibaba Cloud CDN, you are charged CDN outbound traffic fees, origin traffic fees, and API operation calling fees.
For scenarios such as accelerated object uploads and accelerated downloads of non-static objects, we recommend that you use the transfer acceleration feature of OSS to accelerate data transfer. For more information, see Enable transfer acceleration.
Use the OSS console
Map a custom domain name to a bucket.
Log on to the OSS console.
In the left-side navigation pane, click Buckets. On the Buckets page, find and click the desired bucket.
In the left-side navigation pane, choose Bucket Settings > Domain Names.
On the Domain Management page, click Map Custom Domain Name.
In the Map Custom Domain Name panel, enter the domain name that you want to map to the bucket in the Domain Name field.
ImportantDo not turn on Add CNAME Record Automatically.
If a domain conflict error occurs, the domain name is mapped to another bucket. To resolve this issue, you can map another domain name to the bucket or verify the ownership of the domain name to forcibly map the domain name to the bucket. If you verify the ownership of the domain name to forcibly map the domain name to the bucket, the mapping between the domain name and the previous bucket is removed. For more information, see Map custom domain names.
Click Submit.
Configure CDN acceleration.
In the domain name list, click Not Configured in the Alibaba Cloud CDN column of the domain name that you want to manage.
On the Add Domain Name page, configure the parameters. The following table describes the parameters. For more information, see Add a domain name.
Click Next, and then click Return to Domain Name List.
In the domain name list, record the CNAME of the domain name.
Add a CNAME record.
If the domain name is not hosted by Alibaba Cloud, you must add a CNAME record to the Domain Name System (DNS) of your DNS provider. For more information about how to add a CNAME record on Tencent Cloud (formerly known as DNSPod) or Xinnet, see Add a CNAME record for a domain name.
In this example, Alibaba Cloud DNS is used to describe how to add a CNAME record for a domain name.
Log on to the Alibaba Cloud DNS console.
In the left-side navigation pane, click Domain Name Resolution. On the Domain Name Resolution page, click DNS Settings in the Actions column of the domain name for which you want to add a CNAME record.
On the DNS Settings tab, click Add DNS Record. In the Add DNS Record panel, configure the parameters. The following table describes the parameters.
Parameter
Description
Record Type
The type of the record that you want to add. In this example, CNAME is selected.
Hostname
The host record based on the prefix of the domain name.
To add a root domain, such as
aliyun.com
, enter @.To add a subdomain name, enter the prefix of the subdomain name. If the domain name is
abc.aliyun.com
, enter abc.To map all subdomain names to the public domain name of the bucket, enter *.
DNS Request Source
The DNS line that is used to resolve the domain name. To allow the system to select the optimal line, we recommend that you select Default for this parameter.
Record Value
Enter the CNAME value that is recorded in Step 2.
TTL Period
The interval at which the record is updated. Retain the default value.
Click OK.
A new CNAME record immediately takes effect. A modified CNAME record requires up to 72 hours to take effect.
Enable auto CDN cache update.
In the OSS console, go to the Domain Names page and turn on Auto CDN Cache Update for the domain name.
If you want to configure auto CDN cache update for specific operations, click Supported Operations in the Auto CDN Cache Update column of the domain name and select the operations that can trigger auto CDN cache update. The following table describes the supported operations.
Operation
Description
PutObject
Uploads an object by using simple upload. For more information, see Simple upload.
PostObject
Uploads an object by using form upload. For more information, see Form upload.
CopyObject
Copies an object. For more information, see Copy objects.
AppendObject
Appends content to an appendable object. For more information, see Append upload.
CompleteMultipartUpload
Uploads an object by using multipart upload or resumable upload. For more information, see Multipart upload.
DeleteObject
Deletes an object. For more information, see Delete objects.
DeleteObjects
Deletes multiple objects. For more information, see Delete objects.
PutObjectACL
Modifies the access control list (ACL) of an object. For more information, see Object ACLs.
Object or part deletion and storage class conversion based on lifecycle rules no longer trigger the auto CDN cache update feature. When you enable auto CDN cache update, take note of the following items:
You can access updated data on the CDN cache by using a URL in the following format:
CNAME/ObjectName
. However, the updated data cannot be accessed by using URLs that contain request parameters, such as the parameters for Image Processing (IMG) and video snapshots. For example, an accelerated domain nameexample.com
is mapped to a bucket and the a.jpg object in the root directory of the bucket is updated. You can access the updated object on the CDN cache by usingexample/a.jpg
. If you useexample.com/a.jpg?x-oss-process=image/w_100
, you may access the original object.Data update tasks initiated by using the auto CDN cache update feature may fail or be delayed.
Therefore, we recommend that you use the auto CDN cache update feature to update only a small number of objects. If you use the auto CDN cache update feature to update a large number of objects, some update tasks may be discarded due to traffic throttling.
ImportantTo update a large number of objects or pages, we recommend that you call the RefreshObjectCaches operation. For more information, see RefreshObjectCaches.
FAQ
Can I disable auto CDN cache update?
Yes, you can disable auto CDN cache update. Procedure:
On the Domain Names page, click Supported Operations in the Auto CDN Cache Update column of the domain name.
Delete all selected operations.
Click OK.
What do I do if the AccessDenied error occurs when I access an accelerated domain name that is mapped to a bucket?
After you map a custom domain name to a bucket, you can add a specific path to the custom domain name to access the specific OSS resource. Example: http://example.com/test/1.jpg
. If you directly access the custom domain name, such as http://example.com
, the AccessDenied error occurs.
What do I do if the status of the domain name in the Alibaba Cloud CDN column alternates between configured and not configured when I refresh the Domain Names tab in the OSS console after Alibaba Cloud CDN is configured for the domain name?
The configurations of Alibaba Cloud CDN for a domain name require approximately 10 minutes to take effect. Therefore, the status of Alibaba Cloud CDN may alternate on the Domain Names tab. We recommend that you wait 10 minutes after you configure CDN for the domain name before you refresh the tab to check the status.
How do I hide the error information returned from OSS when I retrieve an object from OSS by using Alibaba Cloud CDN?
For more information about how to resolve this issue, see How do I hide the error information returned from OSS when I retrieve an object from OSS by using CDN?
Why am I unable to access the default homepage of a bucket when I retrieve an object from a private bucket by using Alibaba Cloud CDN?
For more information about the causes of and solutions to this issue, see Why am I unable to access the default homepage of a bucket when I retrieve an object from a private bucket by using CDN?
References
To use an accelerated domain name to access OSS resources over HTTPS, you must host your SSL certificates in OSS. For more information, see Host SSL certificates.
To implement cross-origin resource sharing (CORS) when Alibaba Cloud CDN is activated, you must configure CORS rules in the Alibaba Cloud CDN console. For more information, see Configure CORS by using HTTP headers.
To configure hotlink protection after Alibaba Cloud CDN is activated, you must configure hotlink protection in the Alibaba Cloud CDN console. For more information, see Configure a Referer whitelist or blacklist to enable hotlink protection.