To protect your website by using Web Application Firewall (WAF), you must add the domain name of your website to WAF. This topic describes how to add a domain name to WAF in CNAME record mode.
Protection mechanism
After you add the domain name of a website to WAF in CNAME record mode, all traffic to the website is redirected to WAF. WAF filters out malicious traffic and forwards normal traffic to the origin server. This ensures service security and data security of the website. WAF detects and forwards traffic as a reverse proxy cluster.

Prerequisites
A WAF 3.0 instance is purchased. For more information, see Purchase a subscription WAF 3.0 instance and Purchase a pay-as-you-go WAF 3.0 instance.
If you want to add your domain name to a WAF instance in the Chinese Mainland, apply for an Internet Content Provider (ICP) filing for the domain name and make sure that the ICP filing information is valid. For more information, see Scenarios.
NoteWAF instances that reside in the Chinese mainland perform regular validity checks on the ICP filing information of the domain names that are added to WAF. If the ICP filing information of a domain name is invalid, WAF manages the domain name based on the relevant laws and regulations. For example, WAF can stop forwarding requests that are sent to the domain name or delete the configurations of the domain name.
Procedure
Log on to the WAF 3.0 console. In the top navigation bar, select the resource group and the region in which the WAF instance is deployed. You can select Chinese Mainland or Outside Chinese Mainland.
In the left-side navigation pane, click Website Configuration.
On the CNAME Record tab, click Add.
In the Configure Listener step, configure the parameters and click Next. The following table describes the parameters.
Parameter
Description
Domain Name
Enter the domain name that you want to protect. You can enter an exact match domain name, such as
www.aliyundoc.com
, or a wildcard domain name, such as*.aliyundoc.com
. You can enter only one domain name.The first time you add a domain name to WAF, you must verify your ownership of the domain name. You can add the domain name to WAF only after you prove your ownership of the domain name. For more information, see Verify the ownership of a domain name.
NoteYou can use a wildcard domain name to cover all subdomains that are at the same level as the wildcard domain name. For example,
*.aliyundoc.com
can coverwww.aliyundoc.com
andexample.aliyundoc.com
but*.aliyundoc.com
cannot coverwww.example.aliyundoc.com
.A second-level wildcard domain name can cover the second-level parent domain name of the wildcard domain name. For example,
*.aliyundoc.com
can coveraliyundoc.com
.A third-level wildcard domain name cannot cover the third-level parent domain name of the wildcard domain name. For example,
*.example.aliyundoc.com
cannot coverexample.aliyundoc.com
.If you add an exact match domain name and a wildcard domain name that covers the exact match domain name, the protection rules of the exact match domain name take precedence.
Protocol Type
Select the protocol type and ports that are used by the website. Press the Enter key each time you enter a port number.
NoteThe port number that you enter must be within the range of ports that are supported by WAF. To view the HTTP and HTTPS ports that are supported by WAF, click View Port Range. For more information, see View supported ports.
If you select HTTPS, you must configure the HTTPS Upload Type parameter and upload an SSL certificate that is associated with the domain name of the website. This way, WAF can protect and listen to the HTTPS traffic of the website.
Specify the method that you want to use to upload an SSL certificate.
If you select HTTPS and upload a certificate, you can perform the following operations based on your business requirements:
If your website supports HTTP/2, select HTTP2 to protect HTTP/2 requests.
NoteHTTP/2 uses the same ports as HTTPS.
Advanced Settings
Whether Layer 7 Proxy, Such as Anti-DDoS Pro, Anti-DDoS Premium, or Alibaba Cloud CDN, Is Deployed in Front of WAF
Specify whether a Layer 7 proxy is deployed in front of WAF. Layer 7 proxies include Anti-DDoS Pro, Anti-DDoS Premium, and Alibaba Cloud CDN. Default value: No. Valid values: Yes and No.
More Settings
Resource Group
Select the resource group to which you want to add the domain name from the drop-down list. If you do not select a resource group, the domain name is added to the default resource group.
NoteYou can use Resource Management to create resource groups and manage resources within your Alibaba Cloud account by department or project. For more information, see Create a resource group.
In the Configure Forwarding Rule step, configure the parameters and click Submit. The following table describes the parameters.
Parameter
Description
Load Balancing Algorithm
If you specify multiple origin server addresses, select a Load Balancing Algorithm for WAF to forward back-to-origin requests to the origin servers. Valid values:
Origin Server Address
Enter the public IP address or domain name of the origin server. The IP address or domain name is used to receive the back-to-origin requests that are forwarded by WAF. Valid values:
Advanced HTTPS Settings
Other Advanced Settings
In the Add Completed step, obtain the CNAME that is assigned by WAF to the domain name. Modify the DNS record to map the domain name to the CNAME. For more information, see Modify a DNS record.
ImportantBefore you modify the DNS record, make sure that the following prerequisites are met:
The forwarding configurations of your website are correct and in effect. If you change the DNS record before the forwarding configurations of your website take effect, service interruptions may occur. For more information, see Verify domain name settings.
The WAF back-to-origin IP addresses are added to the IP address whitelist of the third-party firewall that is used by the origin server. This prevents normal requests that are forwarded by WAF from being blocked. On the CNAME Record tab, click Back-to-origin CIDR Blocks above the domain name list to view and copy back-to-origin CIDR blocks of WAF. For more information, see Allow access from back-to-origin CIDR blocks of WAF.
After you complete the preceding configurations, you can perform the following operations to check whether the domain name is added to WAF:
Enter the domain name in the browser. If you can access the website, the domain name is added to WAF.
Enter the domain name and malicious code such as
<Protected domain name>/alert(xss)
andalert(xss)
. If a 405 error page appears, the attack is blocked and the domain name is protected by WAF.
More operations
View the DNS resolution status of a domain name
WAF checks the DNS resolution status of protected domain names and identifies domain names whose DNS records are abnormal. You can view the DNS resolution status of the domain names that you added to WAF in the domain name list and modify the DNS records based on the error messages that are displayed in the WAF console.

DNS status | Description | Procedure |
The DNS resolution is normal. | The domain name is mapped to WAF. | None. |
The DNS resolution is abnormal. An A record is used. | An A record is used and service interruptions may occur. | Delete the A record and add a CNAME record to map the domain name to the CNAME that is provided by WAF. For more information, see Modify a DNS record. |
The DNS resolution is abnormal. An invalid WAF IP address is used. | An A record is used and the domain name is mapped to an invalid WAF IP address. Service interruptions may occur. | Delete the A record and add a CNAME record to map the domain name to the CNAME that is provided by WAF. For more information, see Modify a DNS record. |
The DNS resolution is abnormal. An invalid CNAME is used. | A CNAME record is used and the domain name is mapped to an invalid CNAME. | Modify the CNAME record to map the domain name to the CNAME that is provided by WAF. For more information, see Modify a DNS record. |
The issue of unknown DNS resolution occurs. A proxy is deployed. | A Layer 7 proxy is used in front of WAF and the back-to-origin address is not the CNAME that is provided by WAF. | Check whether the back-to-origin address is the CNAME that is provided by WAF. |
The verification timed out. | None. | Click the |
No DNS resolution records are found. No DNS records are configured. | No DNS records are configured for the domain name. A CNAME record must be added to map the domain name to WAF. | Add a CNAME record to map the domain name to WAF. For more information, see Modify a DNS record. |
Failed to point to WAF. No DNS records are configured. | The domain name is not mapped to WAF. The CNAME record must be modified to map the domain name to WAF. | Modify the CNAME record to map the domain name to WAF. For more information, see Modify a DNS record. |
Add tags to or remove tags from domain names
You can add tags to a domain name that is added to WAF and search for specific resources by tag.
Modify or delete a domain name that is added to WAF
Before you delete the domain name, you must change the DNS record configuration to the original configuration. For example, modify the DNS record to resolve the domain name to the IP address of the origin server. If you do not change the DNS record, WAF cannot forward the requests that are sent to the domain name to the origin server, and your website cannot be accessed.
Find the domain name that you want to delete or modify and click Edit or Delete in the Actions column.
Configure default SSL or TLS settings
If you add multiple domain names to the same WAF instance, a shared WAF virtual IP address (VIP) is used to listen to traffic to the domain names.
To meet security compliance and compatibility requirements of HTTPS, WAF allows you to configure SSL or TLS settings. Before you perform compliance scan and detection, you can upload an HTTPS certificate for the VIP and disable or enable specific Transport Layer Security (TLS) protocol versions and cipher suits.
If you purchase and enable an exclusive IP address, the configuration takes effect for the exclusive IP address. For more information about exclusive IP addresses, see Exclusive IP addresses.
Click Default SSL/TLS Settings above the domain name list.
In the Default SSL/TLS Settings dialog box, configure the parameters and click OK. The following table describes the parameters.
Parameter
Description
HTTPS Upload Type
Upload the SSL certificate. For more information, see Upload a certificate.
TLS Version
Specify the versions of the TLS protocol that are supported for HTTPS communication. Valid values:
TLS 1.0 and Later (Best Compatibility and Low Security) (default)
TLS 1.1 and Later (High Compatibility and High Security)
TLS 1.2 and Later (High Compatibility and Best Security)
If you want to enable TLS 1.3, select Support TLS 1.3.
HTTPS Cipher Suite
Specify the cipher suites that are supported for HTTPS communication. Valid values:
All Cipher Suites (High Compatibility and Low Security) (default)
Custom Cipher Suite (Select It Based on Protocol Version. Proceed with Caution.)
For information about custom cipher suites, see View supported cipher suites.
Update the SSL certificate bound to a domain name
If the SSL certificate that is bound to a domain name is about to expire or the certificate is changed, such as the certificate being revoked, you must update the certificate.
If the remaining validity period of the certificate is less than 30 days,
is displayed in the domain name list. This indicates that your SSL certificate is about to expire. You must update the certificate at the earliest opportunity.
If you want to receive notifications when the certificate is about to expire, log on to the Certificate Management Service console. Find the certificate that is about to expire and click the
icon in the Notification Reminder column. On the Notification page, enable and configure a notification policy for the certificate.
To prevent service interruptions that are caused by certificate expiration, enable the certificate hosting feature of Certificate Management Service (Original SSL Certificate). If you enable this feature for a certificate, the system automatically applies for a new certificate. For more information, see Certificate Management Service overview.
To update the SSL certificate that is bound to a domain name, perform the following steps:
Renew the certificate or upload a third-party certificate to Certificate Management Service (Original SSL Certificate). For more information, see Certificate renewal or Upload an SSL certificate.
Synchronize the certificate to WAF.
In the Certificate Management Service (Original SSL Certificate) console, deploy the certificate to WAF. For more information, see Deploy certificates to Alibaba Cloud services.
Upload the certificate in the WAF console.
On the CNAME Record tab of the Website Configuration page, find the domain name whose certificate you want to update and click Edit in the Actions column.
Set the HTTPS Upload Type parameter to Select Existing Certificate and select the new certificate from the drop-down list.
What to do next
After you add a domain name to WAF, the domain name automatically becomes a protected object of WAF and basic protection rules are enabled for the protected object. The name of the protected object is in the "Domain name-waf" format. The protected object is displayed on the Protected Objects page. To go to the Protected Objects page, choose
References
Protection configuration overview: describes the protected objects, protection policies, and protection process.
CreateDomain: describes how to add a domain name to WAF in CNAME record mode by calling the CreateDomain operation.
DescribeDomainDetail: describes how to query the access configurations of domain names that are added to WAF in CNAME record mode by calling the DescribeDomainDetail operation.