When you directly access 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 a 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.
The performance of traditional website architectures is bottlenecked as the access to websites grows because dynamic and static resources in these architectures are not separated. 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 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, the transmission distance is minimized and data access is accelerated.
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 the storage architecture.
Storage fees and traffic fees are reduced.
In this architecture, storage fees for OSS buckets, downstream traffic fees for CDN, and a small amount of back-to-origin traffic fees are incurred. 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 name, second-level domain name, 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, oss.example.com is used.
Business Type: Select Dynamic Acceleration.
Origin Information: Select OSS Domain. Select the domain name of the bucket for which you want to accelerate access, port, and acceleration region.
Click Next, and then click Return.
Wait until the status of the domain name is 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 corresponding 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: Retain the default values.
Click Confirm. Wait a few minutes, and then run the ping command to check whether the accelerated domain name takes effect. If the results 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. Click View Details in the Actions column corresponding 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 the browser to view the details. As shown in the following figure, 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 to access the object.
In the View Details panel of the object, turn on HTTPS.
Log on to the DCDN console. Click Domain Names. Click the accelerated domain name that you add.
In the left-side navigation pane, click HTTPS. In the HTTPS Certificate section, click Modify.
After you complete the settings, you can access the object by using HTTPS. For more information, see Configure HTTPS certificates.