You can use Alibaba Cloud CDN to accelerate the retrieval of resources from an Elastic Compute Service (ECS) instance. This topic describes how Alibaba Cloud CDN accelerates content delivery and how to use Alibaba Cloud CDN to accelerate the retrieval of resources from an ECS instance.
Benefits
ECS is an infrastructure as a service (IaaS) that provides stable, reliable, and elastic cloud computing services with excellent performance. Alibaba Cloud CDN can accelerate static content delivery. ECS instances that are used as origin servers provide the following benefits:
All requests that are destined for the origin server are redirected to points of presence (POPs). This reduces loads on the origin server.
You are charged for outbound data transfer from Alibaba Cloud CDN instead of outbound data transfer over the Internet. Outbound data transfer from Alibaba Cloud CDN is billed at a lower price.
Clients retrieve static resources from the nearest POPs. This minimizes the network transmission distance and ensures the quality of data transmission.
How it works
If the origin server is an ECS instance, Alibaba Cloud CDN caches static resources, including scripts, images, audio files, and video files, on POPs. Clients can retrieve the cached resources from the nearest POPs. Dynamic resources, such as data from web programs and databases, are returned from the ECS instance to clients.
If you want to accelerate the retrieval of dynamic resources from an ECS instance, use Dynamic Content Delivery Network (DCDN). For more information, see What is DCDN?
The following figure shows how Alibaba Cloud CDN accelerates the retrieval of resources from an ECS instance.
Sample scenario
The website image.example.com requires acceleration for image retrieval from an ECS instance. The following table describes the business information and requirements.
Item | Description | Example |
Domain name | The domain name that is accelerated by Alibaba Cloud CDN. | image.example.com |
Business type | Determine the business type based on the website content. If the website distributes images, set the business type to Image and Small File. | Image and Small File |
Acceleration region | The region where the website visitors are located. | Chinese Mainland Only |
Origin server domain name | You can select Site Domain or IP.
| ecs.example.com Note The domain name of the origin server is used in this example. |
Other services | Enable other features based on your business requirements. |
|
Procedure
The following procedure shows how to use Alibaba Cloud CDN to accelerate the retrieval of resources from an ECS instance. The preceding scenario is used as an example.
Step 1: Make preparations
An Alibaba Cloud account is created and real-name verification is completed for the account. For more information, visit the Sign up to Alibaba Cloud and Real-name Registration pages.
Alibaba Cloud CDN is activated. For more information, see Activate Alibaba Cloud CDN.
An ECS instance is created. For more information, see Create an instance.
The domain name that you want to accelerate is prepared.
Step 2: Add the domain name that you want to accelerate
Log on to the Alibaba Cloud CDN console.
In the left-side navigation pane, click Domain Names. On this page, click Add Domain Name and configure the following parameters. The scenario that is described in Sample scenario is used an as example.
NoteThe first time a domain name is added to Alibaba Cloud CDN, Alibaba Cloud CDN verifies the ownership of only the root domain name. For more information, see Verify the ownership of a domain name. If the root domain name has already passed ownership verification, ignore the message.
For information about the parameters and usage notes, see Step 1: Configure business information.
Domain Name to Accelerate: Enter
image.example.com
.Business Type: Select Image and Small File.
Region: Select Chinese Mainland Only.
Click Add Origin Server to add an origin server.
Set the Origin Info parameter to Site Domain or IP, and then enter the domain name of the origin server or the public IP address of the ECS instance that is used as the origin server. The domain name
ecs.example.com
of the origin server is used in this example. Use the default values for other parameters.NoteFor information about the parameters and usage notes, see Step 2: Set up origin servers.
After you add the origin server, click Next.
Wait for manual verification to complete.
After the domain name passes the verification, the status of the domain name changes to Enabled. In this case, the domain name is added to Alibaba Cloud CDN.
View the CNAME that is assigned to the domain name when the value in the Status column changes to Enabled. The CNAME for the domain name that is used in this example is
image.example.com.w.kunlunsl.com
.
Step 3: Configure the domain name
To improve acceleration performance, secure data transmission, and accelerate content delivery, you can enable the corresponding features based on your business requirements.
In the Alibaba Cloud CDN console, go to the Domain Names page, find the domain name that you want to manage, and then click Manage.
Configure the features based on your business requirements. The following table describes the features.
Feature
Description
References
Increase the cache hit ratio
Specify a time-to-live (TTL) value for cached resources based on the following rules to increase the cache hit ratio:
Specify a TTL of one month or longer for static files that are infrequently updated, such as images and application packages.
Specify a TTL based on your business requirements for static files that are frequently updated, such as JavaScript and CSS files.
Specify a TTL of 0 seconds to disable caching for dynamic files, such as PHP, JSP, and ASP files.
Specify the site to which POPs redirect requests
If multiple sites are hosted on your origin server, and the site on which the requested content resides is different from the site to which the accelerated domain name points, you need to configure an origin host. The origin host specifies the site to which Alibaba Cloud CDN redirects requests.
Accelerate file distribution on POPs
After you enable the range origin fetch feature, the ECS instance that functions as the origin server returns the file chunk that is specified by the Range header to POPs. This reduces origin traffic and accelerates content delivery.
NoteThe range origin fetch feature is suitable for scenarios that involve large file distribution, such as audio and video streaming. The range origin fetch feature is not suitable for small file distribution scenarios. You do not need to enable the range origin fetch feature when you use Alibaba Cloud CDN to accelerate the delivery of images.
Increase the cache hit ratio
Increase file distribution efficiency
After you enable parameter filtering, POPs remove parameters that follow the question mark (
?
) from request URLs. This way, requests that carry different query strings but are destined for the same resource can hit the cache. This increases the cache hit ratio and reduces origin traffic.Protect websites from hotlinking
After you configure a Referer whitelist or blacklist, Alibaba Cloud CDN allows or blocks requests based on user identities. If a request is allowed, Alibaba Cloud CDN returns the URL of the requested resource. If a request is blocked, Alibaba Cloud CDN returns the HTTP 403 status code.
Configure a Referer whitelist or blacklist to enable hotlink protection
Protect websites from hotlinking and IP theft
URL signing cannot be performed without the origin server. The origin server generates signed URLs based on the URL signing settings on the POPs. After you enable URL signing, only requests that pass authentication can access resources on POPs.
Step 4: Add a CNAME record
You need to add a CNAME record to the system of your DNS service provider to map the domain name to the CNAME before requests can be redirected to POPs. Otherwise, CDN acceleration cannot take effect.
In the following example, Alibaba Cloud DNS is used to show how to add a CNAME record.
For more information, see Add a CNAME record for a domain name.
Log on to the Alibaba Cloud DNS console with the Alibaba Cloud account to which the accelerated domain name belongs.
Go to the Domain Name Resolution page, find the root domain name of the accelerated domain name example.com, and then click DNS Settings in the Actions column.
Click Add DNS Record to add a CNAME record.
Record Type: Select CNAME.
Hostname: Enter
image
.Record Value: Enter the CNAME that is assigned to the accelerated domain name. In this example,
image.example.com.w.kunlunsl.com
is used.Use the default values for other parameters.
Check whether the CNAME record takes effect.
Method 1: Use the Alibaba Cloud CDN console
Log on to the Alibaba Cloud CDN console and navigate to the Domain Names page.
Find the domain name and move the pointer over the CNAME Status column. If the CNAME status is Configured, the CNAME has taken effect.
NoteIf you add a CNAME record, it takes effect immediately. If you modify a CNAME record, it takes 10 minutes for the update to take effect because the default TTL value of a CNAME record is 10 minutes. During this period, the status of the domain name may be displayed as Pending Configuration in the Alibaba Cloud CDN console until the update takes effect. The actual time period varies based on the TTL value that you specify for the CNAME record.
Method 2: Run the nslookup command
Start Command Prompt in Windows or Terminal in macOS or Linux.
Run the nslookup -type=CNAME domainName command. If the CNAME in the output is the same as the CNAME that is assigned to the domain name in the Alibaba Cloud CDN console, Alibaba Cloud CDN acceleration takes effect for the domain name.