This topic describes how Alibaba Cloud CDN works, as well as key configurations and their functionalities, to help you quickly activate and configure Alibaba Cloud CDN.
In this topic, www.example.com
is used as the example domain name, and 10.10.10.1
is the corresponding IP address.
How Alibaba Cloud CDN works
If you are new to Alibaba Cloud CDN, we recommend that you take a few minutes to read this section. If you are already familiar with the principles of CDN, you can skip this section.
How Alibaba Cloud CDN works
When you enter a URL in a browser, almost instantly, a web page, image, video, or audio file appears on your screen. Actually, this process involves a complex series of software and hardware parsing and forwarding operations. The following part breaks down a simple example request to demonstrate how Alibaba Cloud CDN accelerates content delivery.
1. Common request process
A client visits the www.example.com
domain to access an image. The browser cannot directly resolve the IP address of the server that hosts the image from the domain name. In this case, the browser first queries a DNS server to obtain the IP address 10.10.10.1
that is mapped to the domain name. Then, the browser uses the IP address to locate the server and fetches the required image.
A domain name is like the name of a person, and an IP address is their address. Just like you need to look up the address of a person by using their name, a network request uses a domain name to find the relevant IP address.
A DNS server acts as a large database that stores mappings between domain names and IP addresses. For more information about DNS servers and domain names, see Terms.
2. Request process with Alibaba Cloud CDN
As the number of requests destined for images by using www.example.com
increases, the server may respond increasingly slowly due to factors such as the server configuration and network environment. This is where Alibaba Cloud CDN comes in. It provides an effective solution to accelerate response times.
Alibaba Cloud CDN works as a cache system that sits between the server and client in the network topology. When a client initiates a request to Alibaba Cloud CDN, the system first checks whether the requested image is cached. If it is, the cached image is directly returned to the browser. If not, Alibaba Cloud CDN requests the image from the server, caches it, and then sends the response to the client who initiated the request.
Accelerating content delivery is only the basic feature of Alibaba Cloud CDN. For more information about Alibaba Cloud CDN and its advanced features, see What is Alibaba Cloud CDN?
Alibaba Cloud CDN accelerates content delivery beyond the server architecture, without requiring any modifications to the server business code.
The actual request process is much more complex. This simplified explanation is only intended to explain how Alibaba Cloud CDN works.
Quick start
Compared with other acceleration methods, Alibaba Cloud CDN does not require any modifications to the business code of the server. You can enable content delivery acceleration with only a few simple configurations. The following section describes how to configure Alibaba Cloud CDN by using the preceding example domain name and IP address.
Before you connect a domain name to Alibaba Cloud CDN, complete the following operations:
1. Add a domain name and origin server
Configure a domain name
To enable acceleration for your domain name, you must add your domain name to Alibaba Cloud CDN.
Add a domain name
Log on to the Alibaba Cloud CDN console.
In the left-side navigation pane, click Domain Names.
Click Add Domain Name. In the Specify Domain Name Information step, configure Region, Domain Name to Accelerate, and Business Type. Keep the default settings for other parameters.
NoteDomain Name to Accelerate specifies the domain name that you want Alibaba Cloud CDN to speed up and that is accessed by users. In this example, enter
www.example.com
.Region: Select a service location based on your business needs. In this example, select Chinese Mainland Only.
Business Type: In this example, select Image and Small File.
For more information about the configuration items, see Configure business information.
Verify the domain ownership
To make sure that the domain name you added belongs to you, Alibaba Cloud CDN needs to verify the ownership of the domain name. Skip this step if you have previously completed verification or if you do not receive the verification prompt when configuring the domain name.
Verify the domain ownership
ImportantDo not close the Verification page before the verification is complete.
Use a DNS record (Recommended)
On the verification page, click the Method 1: DNS Settings tab and record the values of the Host and Value parameters.
Add a TXT record in the system of your DNS provider. The following example demonstrates how to add a TXT record to Alibaba Cloud DNS. You can use similar methods to add TXT records to other DNS providers, such as Tencent Cloud and Xinnet.
Configure a TXT record
Log on to the Alibaba Cloud DNS console.
On the DNS resolution page, find the root domain
example.com
and click DNS Settings in the Actions column.Click Add DNS Record. In the dialog box that appears, select TXT for Record Type parameter, set Hostname and Record Value to the values that are obtained in Step 1. Keep the default settings for other parameters.
Click OK.
NoteA root domain is the main address for a website. It is the most basic level of a website's online presence. All webpages, email servers, and other services are built on a root domain. For example, in
shop.example.com
andblog.example.com
,example.com
is the root domain, and "shop." and "blog." are subdomains that extend the functionality of the root domain.
After the TXT record takes effect, go to the Alibaba Cloud CDN console, and click Verify.
If the domain name fails the verification, check whether the TXT record is entered correctly. Wait for the TXT record to take effect and try again. The domain name
image.example.com
is used in the following examples to check whether the TXT record is valid.Windows
Open Command Prompt in Windows, and run the nslookup -type=TXT verification.example.com command. You can check whether the TXT record is valid based on the output.
macOS/Linux
Open Terminal in macOS or Linux, and run the nslookup -type=TXT verification.example.com command. You can check whether the TXT record is valid based on the output.
NoteIn the nslookup command, you need to replace the hostname in the domain name with "verification". For example, if the domain name is
help.aliyun.com
, enterverification.aliyun.com
in the nslookup command.If you add a TXT record, the TXT record immediately takes effect. If you modify a TXT record, the amount of time that is required for the updates to take effect is based on the time to live (TTL). The default TTL is 10 minutes.
If nslookup is not installed on Linux, you can run the yum install bind-utils command on CentOS or the apt-get install dnsutils command on Ubuntu to install nslookup.
Upload a verification file
On the verification page, click the Method 2: Verification File tab.
Download the
verification.html
file.Upload the verification file to the root directory on the server of the root domain. The server can be an Elastic Compute Service (ECS) instance, an Object Storage Service (OSS) bucket, a Cloud Virtual Machine (CVM) instance, a Cloud Object Storage (COS) instance, or an Elastic Compute Cloud (EC2) instance. For example, if the domain name is
www.example.com
, you need to upload the file to the root directory ofexample.com
.After you make sure that the verification file is accessible from
http://example.com/verification.html
, click Verify.Alibaba Cloud CDN accesses
http://example.com/verification.html
on your server for verification.If the record value in the file is the same as the record value in the verification file, the verification is successful.
Otherwise, the verification fails. Make sure that the preceding URL is accessible and the file that you uploaded is valid.
Set up an origin server
An origin server is a web server where you run your business. You need to configure the origin information so that Alibaba Cloud CDN can retrieve resources from your origin server when the requested resources are not present in the cache.
Set up an origin server
After you configure the business information for the domain name, click Add Origin Server in the Origin Servers section.
In the Add Origin Server dialog box, select the type of the origin and enter the origin address. Keep the default settings for other parameters.
NoteThis example uses
10.10.10.1
as the IP address of the origin server.If you want to speed up the distribution of resources stored in an OSS bucket, select OSS Domain for Origin Info.
If the resource that you want to accelerate is deployed on an ECS instance, select IP for Origin Info and enter the public IP address of the ECS instance.
If the resource that you want to accelerate is hosted on a server and cannot be accessed by using an IP address, select Site Domain for Origin Info and enter the domain name of the origin server. The origin domain name must be different from the accelerated domain name. Otherwise, a DNS resolution loop occurs, and requests cannot be redirected to the origin server.
If the resource that you want to accelerate is an Alibaba Cloud Function Compute instance, select Function Compute Domain for Origin Info. Then, select the region and domain name as needed.
For more information about the configuration items, see Set up origin servers.
For information about the best practices of using Alibaba Cloud CDN for OSS, see Use Alibaba Cloud CDN to accelerate the delivery of resources from OSS buckets.
2. Configure a CNAME record
Before you connect your domain to Alibaba Cloud CDN, requests for the domain go straight to the origin server. After you connect the domain name to Alibaba Cloud CDN, requests are first sent to the nearest point of presence (POP). Alibaba Cloud CDN then determines whether to route the request to the origin server. To ensure a seamless transition from direct origin access to Alibaba Cloud CDN-enabled access, you need to configure a CNAME record.
A CNAME record is a type of DNS record that points one domain name to another. For more information about CNAME records, see CNAME record overview.
Add a CNAME record
Log on to the Alibaba Cloud CDN console and navigate to the Domain Names page, find the domain name that you added, and copy the CNAME of the domain name.
Add a CNAME record to the DNS settings of the domain name. The procedure to add a CNAME record varies with your DNS provider. In this topic, Alibaba Cloud and Tencent Cloud are used as examples.
Alibaba Cloud
If your DNS provider is Alibaba Cloud, perform the following steps to add a CNAME record for the domain:
Log on to the Alibaba Cloud DNS console by using the Alibaba Cloud account to which the domain name belongs.
On the DNS resolution page, find the root domain
example.com
and click DNS Settings in the Actions column.Click Add DNS Record to add a record.
ImportantHostname is the prefix of a domain name. For example, the hostname of
www.example.com
iswww
. If the domain name that you want to accelerate is the root domainexample.com
, enter @ in the Hostname field.A CNAME record cannot share the same hostname with an A record.
If the domain that you want to accelerate has an A record with the same hostname, you must suspend or delete the A record before you configure a CNAME record.
This will cause the domain to be temporarily inaccessible. To reduce the impact on your domain, we recommend that you configure a CNAME record during off-peak hours.
Click OK.
Tencent Cloud
If your DNS provider is Tencent Cloud, perform the following steps to add a CNAME record for the domain:
Log on to the DNSPod console.
On the DNSPod page, click Add Records to add a CNAME record.
Parameter
Description
Example
Hostname
For subdomains, enter the prefix of the subdomain.
For wildcard domains, enter
*
.For root domains, enter
@
.
NoteFor more information about subdomains, see Terms.
Subdomains:
If the domain name to be accelerated is
example.aliyundoc.com
, enterexample
.If the domain name to be accelerated is
www.example.aliyundoc.com
, enterwww.example
.
Wildcard domains:
If the domain name to be accelerated is
.aliyundoc.com
, enter*
.If the domain name to be accelerated is
*.example.aliyundoc.com
, enter*.example
.
Root domains: If the root domain is
aliyundoc.com
and the domain name to be accelerated isaliyundoc.com
, enter@
.
NoteDomain name resolution settings apply to the domain name that you register, such as aliyundoc.com, or the left part of the domain name. When you specify the Hostname parameter, enter the part to be resolved. For example, if the domain name to be accelerated is example.aliyundoc.com, enter example.
Record Type
Select CNAME.
CNAME
DNS Request Source
Select Default from the drop-down list.
We recommend that you keep the default setting.
Record Value
Enter the CNAME of the domain name.
NoteFor example, example.aliyundoc.com, and www.example.aliyundoc.com correspond to different CNAMEs. If you want to accelerate a subdomain, add the second-level domain to Alibaba Cloud CDN. Alibaba Cloud then assigns a CNAME to the subdomain. Alternatively, you can add a wildcard domain name to Alibaba Cloud CDN. Subdomains that match the wildcard domain name are mapped to the CNAME of the wildcard domain name. For more information, see Add a domain name.
www.example.com.w.kunlunsl.com
Weight
You do not need to set this parameter.
N/A
MX
You do not need to set this parameter.
N/A
TTL
Enter a TTL value for the CNAME record. A smaller value indicates that the record is updated quicker.
We recommend that you keep the default setting.
Click OK.
Verify that the configured CNAME takes effect.
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 status is Configured, the CNAME has taken effect.
NoteThe CNAME Status may remain Pending Configuration after your configuration. Refresh the page or check the status 5 minutes later.
Use the nslookup command
Start Command Prompt in Windows or Terminal in macOS or Linux.
Enter nslookup -type=CNAME domainName (example: nslookup -type CNAME www.example.com). If the returned result is the same as the CNAME of the domain name in the Alibaba Cloud CDN console, the CNAME has taken effect.
For more information about CNAME configurations, see Add a CNAME record for a domain name.
3. Configure an SSL certificate
If your domain already supports HTTPS access before you connect it to Alibaba Cloud CDN, you must configure an SSL certificate to enable subsequent HTTPS access.
If your domain does not support HTTPS access and does not require it, skip this section.
Configure an SSL certificate
After you enable HTTPS access, you are charged for HTTPS requests. HTTPS request fees cannot be offset by data transfer plans. To avoid service suspension, make sure that you have sufficient balance in your Alibaba Cloud account, or purchase resource plans for HTTPS requests. For more information, see Billing of HTTPS requests for static content.
Log on to the Alibaba Cloud CDN console.
In the left-side navigation pane, click Domain Names.
On the Domain Names page, find the domain name that you want to manage and click Manage in the Actions column.
In the left-side navigation tree of the domain name, click HTTPS.
In the HTTPS Certificate section, click Modify.
In the Modify HTTPS Settings dialog box, turn on HTTPS Secure Acceleration, and configure other relevant parameters.
NoteIf you have purchased a certificate from Alibaba Cloud Certificate Management Service, set the Certificate Source parameter to SSL Certificates Service and select the purchased certificate from the Certificate Name drop-down list.
If you use a certificate that is issued by a third-party CA, set the Certificate Source parameter to Custom Certificate (Certificate+Private Key). After you configure the Certificate Name parameter, configure the Certificate (Public Key) and Private Key parameters. Then the certificate is saved in Alibaba Cloud Certificate Management Service. You can check the certificate on the SSL Certificates page.
Verify that the HTTPS configuration takes effect.
After you upload an SSL certificate, the certificate takes effect within 1 minute. To check whether the SSL certificate takes effect, you can send HTTPS requests to access resources. If the URL is displayed with an HTTPS icon in the address bar of the browser, such as Google Chrome, HTTPS acceleration is working as expected. After you configure an SSL certificate, take note of the expiration time of the certificate. You need to configure a new certificate before the certificate expires.
NoteFor more information about how to configure an SSL certificate, see Configure an SSL certificate.
4. Check whether Alibaba Cloud CDN takes effect
Check whether Alibaba Cloud CDN takes effect
Use the ping or dig command
Windows: Press Windows + R, type cmd in the Run box that appears, and press Enter. The Command Prompt window is displayed.
macOS: Open Terminal.
Run the check commands.
Run the ping domainName command, such as ping www.example.com.
Run the dig domainName command, such as dig www.example.com.
View the CNAME in the output. If the CNAME is
www.example.com.w.kunlun.com
, Alibaba Cloud CDN has taken effect for the domain.If an IP address is returned, as shown in the preceding figure, use the IP address check tool of Alibaba Cloud CDN to query whether the IP address belongs to an Alibaba Cloud CDN POP.
Check whether an IP address belongs to an Alibaba Cloud CDN POP
Log on to the Alibaba Cloud CDN console.
In the left-side navigation pane, click Tools.
In the IP Address Check section, click Try Now.
Enter the IP addresses that you want to check and click Check.
NoteBoth IPv4 and IPv6 addresses are supported. You can check up to 20 IP addresses at a time. Separate IP addresses with commas (,).
View the check result.
If the checked IP address belongs to an Alibaba Cloud CDN POP, the value of CDN Node is Yes and the values of Region and Provider are the actual region and ISP to which the IP address belongs.
If the checked IP address does not belong to an Alibaba Cloud CDN POP, the value of CDN Node is No, and the values of Region and Provider are Unknown.
Use the response header
Windows: Press Windows + R, type cmd in the Run box that appears, and press Enter. The Command Prompt window is displayed.
macOS: Open Terminal.
Run the curl -I resourceURL command, such as
curl -I www.normanjing.cn/10.JPG
.View the response header. If it contains
X-Cache
,X-Swift-SaveTime
, andX-Swift-CacheTime
, Alibaba Cloud CDN has taken effect for the domain.NoteX-Cache: If the value of this field is MISS, the cache is missed and the request is redirected to the origin server. If the value of this field is HIT, the cache is hit and the cached resource is returned.
X-Swift-CacheTime: specifies the TTL period of a resource that is cached on POPs. If the value is 0, resources cannot be cached.
If the domain fails to be accessed or exceptions occur during the access process after you complete the preceding steps, see Service unavailability and exceptions.
After the preceding configurations are complete, your website is accelerated by Alibaba Cloud CDN. To ensure secure, stable operations of the website, we strongly recommend that you configure security features and cache policies.
Recommended configurations for Alibaba Cloud CDN
1. Configure security settings
Malicious attacks and fraudulent traffic are ubiquitous and can cause sudden spikes in bandwidth consumption or excessive amounts of data transmission. This can result in unexpectedly high costs for your website. Therefore, we strongly recommend that you configure appropriate security measures to prevent such risks.
Configure security settings
Enable log monitoring
Alibaba Cloud CDN supports offline logs and real-time logs. By analyzing the collected logs, you can quickly identify business and security issues and make prompt adjustments. For more information about logs, see Logs and reports.
Log category
Log delay
Billing
Best practice
Offline logs
Within 24 hours
Free of charge
Real-time logs
Within 3 minutes
Charged (Billing rules)
Best practices for shipping and analyzing Alibaba Cloud CDN real-time logs in Simple Log Service
Configure a Referer whitelist or blacklist
Referer-based hotlink protection refers to access control based on the Referer header. You can configure a Referer whitelist or blacklist to control access, protecting your resources from unauthorized access.
You can configure a Referer whitelist to allow only requests from specific domains, such as domains that are related to your website system. This way, you can identify and filter visitors to prevent unauthorized use of website resources. For more information, see Configure a Referer whitelist or blacklist to enable hotlink protection.
Configure real-time bandwidth monitoring
You can use CloudMonitor to monitor the peak bandwidth of CDN domains in real time. When the bandwidth of a domain reaches the specified threshold, you will be notified of the potential risks by text message, email, or DingTalk message. For more information, see Configure alert rules.
Configure high bill alerts
You can use the following features to monitor and limit expenses. To configure the features, move the pointer over Expenses in the top navigation bar of the console and select Expenses and Costs.
High bill alerts: If you enable this feature, the system sends an alert by text message when a daily bill exceeds the alert threshold that you specified.
Service suspension protection: If you disable this feature, the service immediately stops running after a payment becomes overdue to prevent high overdue payments.
High bill alerts: After this feature is enabled, notifications are sent to you by text message if a daily bill reaches a specified amount.
NoteTo ensure the integrity of statistics and accuracy of bills, Alibaba Cloud CDN issues a bill about 3 hours after a billing cycle ends. Therefore, the time when fees are deducted from your account balance may be later than the time when the resources are consumed within the billing cycle. As a result, the consumption details of resources are not provided in the bill. This is a common practice among most CDN vendors.
The following content introduces more security policies.
Other security policies
Access control
Feature | Description |
URL signing | URL signing allows points of presence (POPs) to work with your origin servers to protect origin resources from unauthorized use. For more information, see Configure URL signing. |
Remote authentication | After you enable remote authentication, POPs redirect user requests to a specific authentication server. The authentication server verifies the user requests to prevent resources from being accessed by unauthorized users. For more information, see Configure remote authentication. |
IP address blacklist or whitelist | After a malicious attack or traffic spike occurs, you can use the real-time log analysis feature to check whether your domain is frequently accessed by an IP address. If a malicious IP address is identified, you can add it to a blacklist. For more information, see Configure an IP address blacklist or whitelist. |
User-Agent blacklist or whitelist | After a malicious attack or traffic spike occurs, you can use the real-time log analysis feature to identify the User-Agent headers associated with malicious requests. Then, you can configure a User-Agent blacklist or whitelist to block future requests that contain the identified User-Agent header. For more information, see Configure a User-Agent blacklist or whitelist. |
Traffic management
Feature | Description |
Bandwidth cap | To limit the amount of bandwidth resources that a domain name can consume, you can specify a bandwidth cap for the domain name. After the bandwidth of the domain name reaches the specified bandwidth cap, Alibaba Cloud CDN disables acceleration for the domain name and the domain name is resolved to an invalid address. This prevents unexpected high bills. For more information, see Configure a bandwidth cap. |
Traffic throttling for individual requests | Traffic throttling for individual requests allows you to limit the downstream speed for all requests that are sent to POPs. This feature can be used in website operations, such as game releases. This way, you can limit the overall peak bandwidth of accelerated domain names. For more information, see Configure traffic throttling for individual requests. |
Bandwidth throttling | If the daily peak bandwidth of your domain name is greater than 10 Gbit/s and you want to throttle Alibaba Cloud CDN bandwidth for the domain name, submit a ticket. Important
|
If your domain suffers an attack or has an unexpectedly high bill, troubleshoot the issue by referring to Prevent data transmission abuse.
2. Recommended configurations
After you add a domain name to Alibaba Cloud CDN, we recommend that you configure a cache TTL and HTML optimization. These features help increase the cache hit ratio, reinforce security, and improve content retrieval efficiency.
Recommended configurations
Cache TTL and request parameter ignoring
In most cases, slow content delivery is related to low cache hit ratios. We recommend that you specify a proper cache TTL and configure query parameter ignoring to increase the cache hit ratio.
Scenario
Description
Reference
Low cache hit ratio and slow content retrieval
The time-to-live (TTL) value for cached content is smaller than required or no cache expiration rule is created, which causes requests to be frequently redirected to the origin server. In this case, you need to specify a proper TTL value to increase the cache hit ratio and accelerate content retrieval.
We recommend that you specify a TTL value based on the following rules:
Specify a TTL value of one month or longer for static files that are infrequently updated, such as images and application packages.
Specify a TTL value based on your actual workloads for static files that are frequently updated, such as JavaScript and CSS files.
By default, client requests are redirected to the origin server with the complete URLs retained, including parameters that follow the question mark (
?
). After you enable the parameter ignoring feature, the parameters that follow the question mark (?
) in the request URL are ignored when the client retrieves resources from the origin server. This improves the cache hit ratio and reduces the number of origin requests.For more information about the causes of low cache hit ratios, see Troubleshoot low cache hit ratios.
Bandwidth monitoring and alerts
To prevent bandwidth spikes caused by attacks, you can configure the monitoring and alerting features to monitor bandwidth values. Alternatively, you can specify a bandwidth cap.
Scenario
Description
Reference
Prevent high bandwidth values
You can specify a bandwidth cap. If a bandwidth value during a statistical period exceeds the bandwidth cap, Alibaba Cloud CDN suspends acceleration and resolves the domain name to an invalid address
offline.***.com
, which cannot be accessed.You can configure alert rules in CloudMonitor to monitor bandwidth values. This allows you to detect and manage bandwidth anomalies at the earliest opportunity.