When you access Object Storage Service (OSS) resources, the access speed depends on the region in which the buckets are located and is limited by the downstream bandwidth of OSS. Alibaba Cloud Content Delivery Network (CDN) provides higher bandwidth. If you use CDN to access OSS resources, CDN caches the resources on CDN nodes closest to your region and distributes the resources to you from the nodes. This way, you can access OSS resources more quickly at lower costs. This topic describes how to use CDN to accelerate access to OSS.
In traditional website architectures, dynamic and static resources are not separated. Therefore, the performance of a traditional website is bottlenecked when access to the website grows. The following figure shows a traditional website architecture.
You can use an architecture in which dynamic and static resources are separated to resolve the performance problem when the website is accessed by a large number of users. The following figure shows an architecture in which dynamic and static resources are separated.
This architecture separates and distributes resources in the following methods:
Stores dynamic resources such as web applications and databases on Elastic Compute Service (ECS) instances.
Stores static resources such as images, video and audio files, and static scripts in OSS buckets.
Uses OSS buckets as the origins of CDN and distributes objects cached on the node closest to the region in which the user is located to accelerate data access.
This architecture has the following benefits:
The workload for web servers is reduced.
OSS resources are cached on and distributed from CDN nodes closest to the regions in which users are located. This way, data access is accelerated because the transmission distance is minimized.
The storage of a large amount of data is supported.
The capacity of OSS buckets can be elastically expanded. You do not need to upgrade your storage architecture.
Storage fees and traffic fees are reduced.
In this architecture, you are charged the storage fees for OSS buckets, downstream traffic fees for CDN, and a small amount of back-to-origin traffic fees. The storage fees for OSS buckets are 50% cheaper than those for the same capacity of cloud disks. The unit price of CDN traffic is only about 30% to 40% of the unit price of OSS outbound traffic over the Internet.
In the following steps, example.com is used as the domain name and oss.example.com is used as the accelerated domain name. You can specify an actual domain name as the accelerated domain name, such as a primary domain, second-level domain, or wildcard domain name.
Add a domain name.
Log on to the DCDN console. Click Domain Names.
Click Add Domain Name. On the page that appears, configure the following parameters:
Domain Name to Accelerate: Enter the domain name that you want to specify as the accelerated domain name. In this example, enter oss.example.com.
Business Type: Select DCDN.
Acceleration Region: Select Mainland China Only.
Origin Information: Select Add Origin Server. On the dialog box that appears, select OSS Domain for Type, and then select the domain name of the bucket for which you want to accelerate access from the drop-down list. Keep the default settings of other parameters. Click OK.
Click Next. Then, click Return.
Wait until the status of the domain name becomes Running. Copy the CNAME of the domain name, which is oss.example.com.w.kunluncan.com in this example.
Resolve the domain name.
Log on to the Domains console. Click Resolve in the Actions column that corresponds to the domain name example.com.
On the Add Record page, configure the following parameters:
Record Type: Select CNAME from the drop-down list.
Host: Enter oss.
Value: Enter the copied CNAME oss.example.com.w.kunluncan.com.
Other parameters: Keep the default settings.
Click OK. Wait a few minutes, and then run the ping command to check whether the accelerated domain name takes effect. If a similar result showed in the following figure is returned, the accelerated domain name takes effect.
Enable auto CDN cache update
Log on to the OSS console. In the left-side navigation pane, click Buckets. On the Buckets page, click the name of the bucket for which you want to accelerate access.
Choose Transmission > Domain Names.
Turn on Auto CDN Cache Update for the accelerated domain name that you add.
View the URL of an object.
Log on to the OSS console. In the left-side navigation pane, click Buckets. On the Buckets page, click the name of the bucket in which the object you want to view is stored.
Click Files. On the page that appears, click View Details in the Actions column that corresponds to the object that you want to view.
In the View Details panel, select the accelerated domain name from the Custom Domain Name drop-down list. In this example, select oss.example.com. As shown in the following figure, the URL of the object starts with the accelerated domain name.
Access the object by using the URL and use the developer tools of your browser to view the details. The following figure shows that the accelerated domain name takes effect and the object is cached on CDN.
Remove the validity period of the URL.
In the View Details panel, click Set ACL.
Select Public Read. Click OK.
(Optional) Configure HTTPS certificates used to access the object.
In the View Details panel of the object, turn on HTTPS.
Log on to the DCDN console. Click Domain Names. On the page that appears, click the accelerated domain name that you add.
In the left-side navigation pane, click HTTPS Settings. In the SSL Certificate section, click Modify.
After you complete the settings, you can access the object by using HTTPS. For more information, see Configure HTTPS certificates.