This topic explains how CDN accelerates resources on an ECS instance and describes the implementation procedure.
Benefits
Using an ECS instance as the origin server for CDN combines scalable IaaS computing with accelerated static resource distribution, providing the following benefits:
All user requests for website resources are routed through CDN, which reduces the load on the origin server.
CDN traffic is charged at a lower rate than the outbound data transfer generated by direct access to an ECS instance.
Clients retrieve resources from the nearest CDN node, which reduces network latency and improves static resource delivery.
How it works
When using an ECS instance as an origin server, CDN caches its static resources—such as scripts, images, and audio/video files—on globally distributed acceleration nodes. Users then retrieve these resources from the nearest CDN node. CDN forwards requests for dynamic content, such as web applications and databases, to the ECS instance.
To accelerate dynamic resources on your ECS instance, you can use Alibaba Cloud ESA. For more information, see What is ESA?.
The following figure shows the technical architecture.
Use case
This topic uses an example website, image.example.com, to demonstrate how to accelerate image resources hosted on an ECS instance.
Parameter | Description | Example |
Website domain name | The domain name to accelerate. | image.example.com |
Business type | This type depends on your website's content. For example, if your website consists mainly of images, the business type is Image and Small File. | Image and Small File |
Acceleration area | The geographic regions of your website visitors. | Chinese mainland only |
Origin domain name | You can use an origin domain name or an IP address.
| ecs.example.com Note This example uses an origin domain name. |
Other services | Other business requirements. |
|
Configuration procedure
Based on the use case, this topic outlines the procedure for accelerating resources on an ECS instance with Alibaba Cloud CDN.

Manual deployment
Prerequisites
You have completed Alibaba Cloud Account Registration and Real-Name Verification.
You have activated Alibaba Cloud CDN.
You have created an ECS instance. For more information, see Create an instance.
You have a domain name to accelerate.
Step 1: Add an accelerated domain name
Log on to the Alibaba Cloud CDN console.
In the left-side navigation pane, choose Domain Names. On the Domain Names page, click Add Domain Name and configure the parameters described in the following table based on the use case.
NoteWhen you add a domain name to the Alibaba Cloud CDN console for the first time, you must verify the ownership of its root domain. For more information, see Verify the ownership of a domain name. Skip this step if you have already verified ownership of the root domain.
For more information about the parameters, see Configure basic and business information.
Domain Name to Accelerate:
image.example.comBusiness Type: Image and Small File
Region: Chinese Mainland Only
Click Add Origin Server and configure the origin server.
For Origin Info, select Origin Domain Name or IP, and enter the origin domain name or the public IP address of the ECS instance. In this example, the origin domain name is
ecs.example.com. You can keep the default values for the other parameters.NoteFor more information about the parameters, see Configure an origin server.
After you configure the origin server, click Next.
Wait for manual review.
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 CDN.
When the domain name status is Enabled, the CNAME for the accelerated domain name is displayed. In this example, the CNAME is
image.example.com.w.kunlunsl.com.
Step 2: Configure the domain name
To improve acceleration performance and access security, you can configure the following 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 click Manage in the Actions column.
Configure the features in the following table based on your business needs.
Use case
Description
Configuration
Improve the cache hit ratio
Set a reasonable cache expiration time to improve the cache hit ratio:
For static files that are infrequently updated, such as images and application installation packages, we recommend that you set the expiration time to one month or longer.
For static files that are frequently updated, such as JavaScript and CSS files, set the expiration time based on your business requirements.
For dynamic files, such as PHP, JSP, and ASP files, we recommend that you set the expiration time to 0s to disable caching.
Specify the site for origin fetch requests from CDN nodes
If your origin server hosts multiple sites, and the site that CDN needs to access is different from the accelerated domain name, you must configure the origin host. Alibaba Cloud CDN uses the host information to retrieve resources from the correct site during origin fetch.
Improve the efficiency of file downloads from the origin
When you enable range origin fetch, CDN nodes can request large files from your ECS origin server in chunks. The instance then responds with only the requested range of content.
NoteThis feature is suitable for distributing large files, such as audio and video. You do not need to configure this feature for image and small file acceleration.
Improve the cache hit ratio
Improve file distribution efficiency
When parameter filtering is enabled, CDN nodes remove the parameters that follow the
?in a URL when generating a cache hash key. This allows requests for the same resource file with different parameters to hit the same cached file, which improves the cache hit ratio and reduces traffic to the origin server.Restrict users who can access CDN resources and prevent hotlinking
By configuring a Referer whitelist or blacklist, you control access based on the Referer header of the request. CDN either allows or denies the request based on your rules. If allowed, CDN serves the resource. If denied, CDN returns a 403 status code.
Prevent hotlinking and unauthorized traffic consumption
URL signing requires coordination with your origin server. The server needs to generate signed URLs according to the authentication algorithm specified in the URL signing configuration on CDN. Once enabled, CDN serves requests only from clients with valid signed URLs, thus preventing unauthorized access.
Nginx configuration for static and dynamic content
If your origin server uses Nginx, you can improve acceleration performance by separating static and dynamic content and applying different CDN caching policies to each.
Static resource cache configuration
For static resource paths, such as /css, /js, and /images:
Cache expiration time: We recommend that you set the cache expiration time to 30 days (2,592,000 seconds). Static resources like CSS, JS, and images are updated infrequently. A longer cache time can significantly improve the cache hit ratio.
Ignore Parameters: We recommend that you enable this feature to prevent multiple cached copies from being generated when URLs contain different query parameters.
Range origin fetch: We recommend that you enable this feature. For large JS/CSS bundle files, CDN nodes can retrieve content in chunks based on the specified range, which reduces origin fetch traffic and response time.
Dynamic resource cache configuration
For dynamic request paths, such as /api or .php files:
Cache expiration time: We recommend that you set the cache expiration time to 0 seconds (no caching) to ensure that each request retrieves the latest data from the origin server.
Origin host configuration
Origin host: Set this to the domain name configured on your Nginx server, such as the domain name
ecs.example.comthat is bound to the ECS instance, not the accelerated domain name.Reason: Nginx uses the
server_namedirective to differentiate between virtual hosts. If the origin host sent by CDN does not match a configuredserver_name, Nginx may route the request to a default site or return an error, preventing CDN from retrieving the correct resources.
Step 3: Configure a CNAME record
You must add a CNAME record at your DNS provider to point your accelerated domain name to the CNAME address provided by CDN. This routes user requests through the CDN network for acceleration.
The following steps show how to add a CNAME record if your DNS provider is Alibaba Cloud DNS.
For more information, see Configure a CNAME record.
Log on to the Alibaba Cloud DNS console by using the account that owns the domain and go to the Public DNS page.
On the Authoritative Domains page, find the root domain (example.com) of the accelerated domain name, and click DNS Settings in the Actions column.
Click Add Record to add a CNAME record.
Type: CNAME
Host Record:
imageRecord Value: Enter the CNAME that you obtained from the Domain Names page, which is
image.example.com.w.kunlunsl.comin this example.Keep the default values for the other parameters.
Verify the CNAME record.
Method 1: Check the status in the Alibaba Cloud CDN console
Go to the Domain Names page in the Alibaba Cloud CDN console.
Find the target domain name and check the CNAME Status column. The status shows Configured once the CNAME record is in effect.
NoteA new CNAME record in Alibaba Cloud DNS takes effect immediately. An updated record takes effect after its TTL expires (the default is 10 minutes). During this propagation time, the status may appear as Pending Configuration.
Method 2: Use the nslookup command
Open the command-line interface on your computer.
Run nslookup -type=CNAME accelerated domain name. If the returned CNAME record matches the CNAME value for the accelerated domain name in the CDN console, this indicates that CDN acceleration has taken effect. For example:
nslookup -type=CNAME image.example.comLast login: xxx xxx ~ % nslookup -type=CNAME image.example.com Server: Address: xxx Non-authoritative answer: image.example.com canonical name = image.example.com.w.kunlunsl.com. Authoritative answers can be found from: