If you enabled a content delivery network (CDN) for your domain name that is at risk of web attacks, we recommend that you use Web Application Firewall (WAF) together with a CDN service, such as Alibaba Cloud CDN, to protect your web services. This topic describes how to use WAF together with CDN to protect web services.
Network architecture
You can deploy WAF and CDN in the following sequence: CDN, WAF, and origin servers. CDN is deployed at the ingress layer to accelerate content distribution. WAF is deployed at the intermediate layer to protect applications. Origin servers can be deployed on Elastic Compute Service (ECS) instances or Server Load Balancer (SLB) instances in virtual private clouds (VPCs) or data centers. Then, traffic is accelerated by CDN and filtered by WAF. Only normal service traffic is forwarded to the origin server. This ensures service and data security.
Prerequisites
- A CDN service is enabled and a domain name is added to the CDN service. For more information, see Getting started with Alibaba Cloud CDN.
- A WAF instance is purchased.
Step 1: Add a domain name to WAF
- Log on to the WAF console. In the top navigation bar, select the resource group and the region to which your WAF instance belongs. The region can be Chinese Mainland or Outside Chinese Mainland.
- In the left-side navigation pane, choose .
- On the Domain Names tab, click Website Access.
- Add the domain name that you want to protect to WAF.
- CNAME record modeNote On the Add Domain Name page, the Access Mode parameter is set to CNAME Record by default. In CNAME record mode, you do not need to modify the value of the Access Mode parameter.
- In the Enter Your Website Information step, configure the parameters and click Next. The following table describes the parameters.
Parameter Description Domain Name Enter the domain name of the website that you want to protect. Protection Resource Select the type of protection resource that you want to use. Protocol Type Select the type of protocol that is supported by your website. Destination Server (IP Address) IP: Enter the public IP address of the SLB or ECS instance on which the origin server is deployed or the IP address of the origin server that is not deployed on Alibaba Cloud. Destination Server Port Specify the port based on the value of the Protocol Type parameter. The port is used by the origin server to provide services. Load Balancing Algorithm If you enter multiple addresses of origin servers, configure this parameter based on your business requirements. Does a layer 7 proxy (DDoS Protection/CDN, etc.) exist in front of WAF Set this parameter to Yes. Enable Traffic Mark Specify whether to enable the traffic marking feature of WAF. Resource Group If you want to manage cloud resources by department or project, select the resource group to which the domain name belongs from the resource group drop-down list. - On the Domain Names tab of the Website Access page, find the domain name that you added to WAF and copy the CNAME that is assigned by WAF to the domain name.
- In the Enter Your Website Information step, configure the parameters and click Next. The following table describes the parameters.
- Transparent proxy mode
- On the Add Domain Name page, set the Access Mode parameter to Transparent Proxy Mode.
- In the Add Domain Name step, configure the parameters and click Next. The following table describes the parameters.
Parameter Description Domain Name Enter the domain name of the website that you want to protect. SLB-based Domains, Layer 7 SLB-based Domains, Layer 4 SLB-based Domains, and ECS-based Domains Select the type of the instance that you want to protect and the port that you want to use to redirect traffic. Does a layer 7 proxy (DDoS Protection/CDN, etc.) exist in front of WAF Set this parameter to Yes. Enable Traffic Mark Specify whether to enable the traffic marking feature of WAF. Resource Group If you want to manage cloud resources by department or project, select the resource group to which the domain name belongs from the resource group drop-down list. - In the Check and Confirm Added Information step, check and confirm the information and click Next.
- Click Completed. Return to the website list and go back to the Domain Names tab of the Website Access page. On the Servers tab, select Resource Instance ID from the Resource Instance ID drop-down list and enter the ID of a resource instance to search for the IP address and the port of the instance that you added to WAF.
- CNAME record mode
- Modify the DNS record. After you add the domain name to WAF, you must modify the DNS record to resolve the domain name to WAF. For more information, see Change a DNS record.
Step 2: Enable WAF protection for a domain name that is added to Alibaba Cloud CDN
- 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 for which you want to enable WAF protection and click Manage in the Actions column.
- In the left-side navigation pane of the page that appears, click Basics. In the Origin Information section, click Add Origin Server. In the Add Origin Server dialog box, configure the parameters and click OK. The following table describes the parameters.
Parameter Description Origin Info - If the domain name is added to WAF in CNAME record mode, select Site Domain and enter the CNAME that you obtained in CNAME record mode.
- If the domain name is added to WAF in transparent proxy mode, select IP and enter the public IP address of the origin server that you obtained in Transparent proxy mode.
Priority Specify the priority of the origin server. A primary origin server has a higher priority than a secondary origin server. Weight Specify the weight of the origin server. If multiple origin servers have the same priority, Alibaba Cloud CDN redirects requests to the origin servers based on the weights. Port Specify the port of the origin server that processes requests. - In the left-side navigation pane of the Domain Names page, click Back-to-origin. On the Configurations tab, verify that Default Origin Host is disabled.
Related operations
If you want to enable WAF protection for a domain name for which Dynamic Route for CDN (DCDN) is enabled, you can enable WAF in the DCDN console. Then, you can use WAF to protect your web services on DCDN nodes. For more information, see Getting started with WAF (new edition).
References
- Add a domain name: adds a domain name to WAF in CNAME record mode.
- Transparent proxy mode: adds a domain name to WAF in transparent proxy mode.
- Add a domain name: adds a domain name to Alibaba Cloud CDN.