0. Effect#
1. Requirements#
- dnspod or other DNS resolution sites with domestic and international diversion functions, this article uses dnspod
- cloudflare account
- Two domain names. The main domain name is the domain name accessed by the user, which is www.vikifish.com in this article, and the auxiliary domain name is used for fallback source, represented as origin.xxx.com in this article.
2. Principle#
The principle of acceleration is actually very simple, which is to configure CNAME through dnspod to direct user access to the specified cloudflare CDN server, and then set the fallback source of the CDN in cloudflare to update the cache from the real server. As shown in the figure:
3. Operation#
The general process is divided into three parts:
- Use dnspod to divert user access to the domain www.vikifish.com for CDN
- Use cloudflare to proxy the real server origin.xxx.com
- Use cloudflare to set the fallback source origin.xxx.com when users access www.vikifish.com through the CDN
dnspod Diversion Configuration#
dnspod configures the domain name you want to give to users, here it is www.vikifish.com (I use a subdomain because this domain is applied for cloudflare, and custom DNS servers charge fees 😭).
Delegate www.vikifish.com to dnspod management
- Tencent Cloud Console --> Cloud Resolution DNS --> My Resolution --> Add Domain Name, add www.vikifish.com. Follow the operation prompts to configure the TXT record at the DNS provider (I am using cf).
- Since a subdomain is added, you also need to configure the NS record at the DNS provider.
- After successful configuration, the domain status in cloud resolution will show normal.
Use dnspod to divert www.vikifish.com
Configuration is as follows:
cloudflare Proxy Real Server#
- Delegate xxx.com to cloudflare
- Configure DNS records to point origin.xxx.com to the website server IP
Set Fallback Policy#
- Manage xxx.com on cloudflare
- Open SSL/TLS --> Custom Hostname, add fallback source, and add origin.xxx.com to the fallback source. After successful addition, the fallback source status will show as "Valid".
- Add a custom hostname, add www.vikifish.com, and use the default configuration.
- At this point, the custom hostname status will be abnormal. Click on it and follow the prompts to add a TXT record in dnspod and wait a moment.
4. Problems Encountered#
- Certificate Issue
Since cf actually retrieves data from origin.xxx.com, the server needs to be configured with the certificate for origin.xxx.com, and the SSL rule should be set to "Full (Strict)". - Error 1034
This is because Cloudflare's edge validation checks do not allow users to point to domains like 1.1.1.1. According to the configuration set by dnspod diversion, directly direct overseas traffic to the source server origin.xxx.com. - Want to access the root domain
If you can customize the DNS server of the domain name, you can change www.vikifish.com in the tutorial to vikifish.com as well. Only a few DNS hosting configurations may differ from the tutorial, but there will be prompts during configuration.
If, like me, the root domain is hosted on cf, you can directly set rules in cf and use the Redirect from Root to WWW template (but accessing the root domain is not as fast as the subdomain due to the additional redirection by cf).
Done!
This article is synchronized and updated to xLog by Mix Space. The original link is https://www.vikifish.com/posts/env/cf-optimize-access-speed-001