Hero-oo

Hero-oo

email

Cloudflare Dual Domain Name Implementation for Domestic Traffic Diversion and Acceleration

0. Effect#

Before Optimization

After Optimization 1

After Optimization 2

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:

CDN Diversion

3. Operation#

The general process is divided into three parts:

  1. Use dnspod to divert user access to the domain www.vikifish.com for CDN
  2. Use cloudflare to proxy the real server origin.xxx.com
  3. 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

  1. 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).
  2. Since a subdomain is added, you also need to configure the NS record at the DNS provider.
  3. After successful configuration, the domain status in cloud resolution will show normal.

cf

dnspod

Use dnspod to divert www.vikifish.com

Configuration is as follows:

dnspod

cloudflare Proxy Real Server#

  1. Delegate xxx.com to cloudflare
  2. Configure DNS records to point origin.xxx.com to the website server IP

Set Fallback Policy#

  1. Manage xxx.com on cloudflare
  2. 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".
  3. Add a custom hostname, add www.vikifish.com, and use the default configuration.
  4. 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#

  1. 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)".
  2. 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.
  3. 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).

cf Redirect

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

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.