Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites

Before you start to read this article, the editor first states his own point of view: if it is not necessary, domestic sites should not use Cloudflare’s CDN service as much as possible. Unless the server used in the WordPress website you built is not in China, there are many domestic CDN services that can meet your website acceleration needs, such as CDN provided by Aliyun, Tencent Cloud, Qiniuyun, UPYUN and other service providers.

, however, if you have to use Cloudflare’s CDN, take a look at the sleele tutorial, which is clear and easy to understand, enjoy!

preface

recently set out to optimize blog access speed Based on the last optimization again, this time I used the cloudflare cdn acceleration scheme I gave up before, and now I have new ideas and new tools. The cdn nodes of

cloudflare are all overseas, and the domestic access speed is not ideal. If the quality of your vps line is good, using cloudflare cdn will slow down. This is my previous idea, but since cloudflare launched the cloudflare partner project, you can use cname parsing through partner for free, so you can use some tricks to achieve custom cdn nodes.


dnspod dns parsing

is intended to be written in logical order, but considering that the actual operation is performed in tool order, let’s start with dns parsing!

in the past, if we wanted to use cloudflare’s free cdn, we had to use cloudflare’s dns parsing, but now we have a partner plan and we can use cname parsing for free. This time we choose dns parsing provided by dnspod. Dnspod also provides d monitoring service. D monitoring can monitor website lines and automatically switch nodes

according to network conditions.
Let’s talk about what is d monitoring first.

what is D monitoring?
D monitoring is: when one of your servers is confirmed to be down, the system will automatically switch you to an available server, and when the failed server is restored, it will automatically switch back to the original ip (Note: the system does not enable D monitoring by default, you need to enable D monitoring manually)
The principle of detection: all monitoring points will initiate a http request to the target server, and when and only if all monitoring points do not get a reply, we will think that the server is down and operate. (it should be noted here that 403 and other error returns only prompt warnings, no ip switching, and more than 500 errors indicate downtime, switching.) to use dnspod dns resolution,

should first register dnspod and hang the domain name on it. This person who is believed to have the ability to build a station will operate it. I will not repeat the

domain name after dnspod dns resolution, do not set d monitoring for the time being. Now you can go to cname.


cloudflare partner

first sign up for the cloudflare account (http://cloudflare.com/)), and then go to cloudflare partner to log in.

I use the cloudflare partner service provided by Benniu: https://cdn.bnxb.com/,

register to log in to the cloudflare partner service of Benniu, and then choose to add a domain name and use cname to access. After the

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites1

BNXB management backend

submits, the cname address is given, and the cname address is entered into the dns resolution of dnspod. The

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites2

CNAME origin-pull setting

will take effect in a while. Check the website under ping to see if you have gone to cloudflare cdn. If you have gone to cloudflare cdn at this time, then the cname address will appear on the ping website. The biggest advantage of connecting


cname to cloudflare cdn is that we can customize the cdn node, so that we can select the cloudflare cdn node with the fastest access in China to speed up the access and prevent the website from being interrupted due to the line under the blessing of d monitoring. Many of the free nodes provided by

cloudflare are ruined, so you need to test them yourself.

I share some ip provided on the Internet, these ip segments, select the ip segment and modify the ip address, fill in the dnspod, for example

, and according to the operator fill in, each operator fill in two nodes, overseas default:172.64.32.56172.64.32.1

24 (recommended mobile, go to Hong Kong)
104.28.14.0 Compact 24 (recommended for moving to Singapore)
104.23.240.0-104.23.243.254 (recommended for China Unicom, China Mobile, unknown line)
108.162.236.1 Universe 24 (recommended by Unicom, USA)
104.20.157.0Compact 24 (recommended by Unicom, go to Japan)
104.16.160.1 Compact 24 (recommended Telecom, Los Angeles)
172.64.0.0 Compact 24 (recommended Telecom, San Francisco)
172.64.32.* (go to Europe)

108.162.236.1 Universe 24 Unicom goes to the United States
172.64.32.1 Compact 24 moves to Hong Kong
104.16.160.1Compact 24 Telecom goes to Los Angeles, USA
172.64.0.0Compact 24 Telecom San Francisco, USA
104.20.157.0 Universe 24 Unicom goes to Japan
104.28.14.0 Universe 24 moves to Singapore

104.18.62.1 Compact 24 Hong Kong hkix.net
104.16.35.1 Big 24 Hong Kong hkix.net
104.16.36.1 Compact 24 Hong Kong hkix.net
104.18.35.1 Big 24 Hong Kong hkix.net
104.18.36.1 Compact 24 Hong Kong hkix.net
104.16.54.1 Compact 24 Hong Kong
104.16.55.1 Compact 24 Hong Kong
104.18.128.1 Compact 24 Hong Kong
104.18.129.1 Universe 24 Hong Kong
104.18.130.1 Universe 24 Hong Kong
104.18.131.1 Universe 24 Hong Kong
104.18.132.1 Universe 24 Hong Kong
104.19.195.1 Compact 24 Hong Kong
104.19.196.1 Universe 24 Hong Kong
104.19.197.1 Universe 24 Hong Kong
104.19.198.1 Compact 24 Hong Kong
104.19.199.1 Compact 24 Hong Kong
# nodes suitable for telecom
104.23.240.*
# the delay of exporting from European countries to the United Kingdom, Germany, the Netherlands and so on is higher than that of the United States, which is suitable for websites in Europe.
172.64.32.*
# although I went to Singapore, the detour of the return route is not good, so it is not recommended
104.16.160.*
# the San Jose route is a little faster than Los Angeles, recommended
108.162.236.*
# Atlanta line, delay is stable, but delay is high
# nodes suitable for mobile
162.158.133.*
# in Denmark, only part of this section of ip is available, you can try it yourself, around the United States
198.41.214.*
198.41.212.*
198.41.208.*
198.41.209.*
172.64.32.*
141.101.115.*
# there are many IP segments moving to Hong Kong, but not all of the above. CF Mobile has achieved good results in both Hong Kong's direct connection and ntt, but some areas still lose packets at night.
172.64.0. *
# this is the way to San Jose, usually Hong Kong is fine
172.64.16.*
# European route. Around
# 1.0.0.1 has a good effect
Telecom part
Most provinces can use 1.0.0.0 directly, with low delay and less packet loss.
# Mobile part
# Singapore
104.18.48.0-104.18.63.255
104.24.112.0-104.24.127.255
104.27.128.0-104.27.143.255
104.28.0.0-104.28.15.255
# Mobile part
# San Jose
104.28.16.0-31.255
104.27.144.0-243.254
104.23.240.0-243.254
# Hong Kong cloudflare1-100g.hkix.net
1.0.0.0-254
1.1.1.0-254
# Hong Kong Direct connection
104.16.0.0-79.255
104.16.96.0-175.254
104.16.192.0-207.255


And

, if you do not want to test so many nodes, or if you are worried about the failure of the nodes, you can write all the record values except the default as1.0.0.1. Cloudflare will judge for yourself, and after parsing, all the dns records will be transferred to1.0.0.1, which looks very show:

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites3

domain name DNS management


opens D monitoring

, click on the icon shown in the following figure, and check all the nodes.

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites4

D monitoring sets

to check the situation of nodes. At present, the latency of free nodes varies from high to low, as long as the node of the corresponding operator line is not red. After the

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites5

DNSPod domain name monitoring

, if you are not satisfied with the node, you can change the node in dnspod, which takes effect quickly. You can check the status of the new node in d monitoring.


cloudflare page rules

cloudflare does not cache the html file by default. Therefore, in order to put as much data in the cloudflare node as possible, we need to set the cache content.

this is cloudflare’s official page rules explanation. I suggest you take a look. It doesn’t matter if you don’t bother to read it. It’s OK to follow my settings:

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites6

Page rules sets

.
Be careful! In order of priority.

sleele.com/wp-admin*
 
sleele.com/*preview=true*
 
sleele.com/*

Cloudflare caching takes time, so it is best to set edge cache ttl for a long time, otherwise it will expire before caching to cdn. The 7 days I set, the background and preview articles are not cached.

inserts another word here, because there are only three rules for a free account, which is not enough for WordPress. In order to save the rules, you need to modify the WordPress login address to change it towp-adminxxxx;

installs theRename wp-login.phpplug-in and changes the login address towp-adminxxxx.

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites7

WordPress background login address


test whether the cache is successful

this may take a while to see the effect, but whether to go to the cdn node can see at that time,

shut down the agent software, open Chrome developer mode,Networktab,Disable cachedisable browser cache, select your own website URL,Headerstag, check whetherRemote Addressis the address previously set in dns parsing.

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites8

cache hit to view

cf-cache-status: HITis to hit cache, checkTimingtag, look atTTFBtime, the shorter the better.

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites9

TTFB Information View solution for incorrect IP address of visitors after


has passed CDN after using cloudflare cdn, the visitor’s ip and message ip will become cloudflare cdn’s ip, and the solution is also very simple. The cloudflare official provides the solution.

Cloudflare includes the visitor’s IP address in the X-Forwarded-For header and the CF-Connecting-IP header.

modifies the Nginx configuration file to add the following to the http content, adding the ip section of cloudflare:

# loads the configuration
Nginx-s reload

location / {
 set_real_ip_from 103.21.244.0/22;
 set_real_ip_from 103.22.200.0/22;
 set_real_ip_from 103.31.4.0/22;
 set_real_ip_from 104.16.0.0/12;
 set_real_ip_from 108.162.192.0/18;
 set_real_ip_from 131.0.72.0/22;
 set_real_ip_from 141.101.64.0/18;
 set_real_ip_from 162.158.0.0/15;
 set_real_ip_from 172.64.0.0/13;
 set_real_ip_from 173.245.48.0/20;
 set_real_ip_from 188.114.96.0/20;
 set_real_ip_from 190.93.240.0/20;
 set_real_ip_from 197.234.240.0/22;
 set_real_ip_from 198.41.128.0/17;
 set_real_ip_from 199.27.128.0/21;
 set_real_ip_from 2400:cb00::/32;
 set_real_ip_from 2606:4700::/32;
 set_real_ip_from 2803:f800::/32;
 set_real_ip_from 2405:b500::/32;
 set_real_ip_from 2405:8100::/32;
 set_real_ip_from 2c0f:f248::/32;
 set_real_ip_from 2a06:98c0::/29;
 # use any of the following two
 real_ip_header CF-Connecting-IP;
 #real_ip_header X-Forwarded-For;
 }

WordPress to accelerate


WordPress is to dynamically generate web pages. In order to further improve the loading speed, you can use

to generate static pages and enable the gzip compression option. Cache Everything can cache the compressed html of gzip into cdn to improve the loading speed. Another Autoptimize plug-in also provides excellent WordPress optimization support.WP Super CacheWP Super Cache page compression enables whether

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites10

WP Super Cache compression works or not

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites11

. In addition, it is recommended to install the official plug-in cloudflare


to manually and automatically clear the cache and view data analysis, which is very useful.

cloudflare plug-in installation

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites12

Speed Test


first of all, the scores of these speed tests can only be used as a reference and do not have much practical significance, especially Google tests.

boce National Speed Test

boce website Speed Test

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites13

about website speed testing, you can read the website speed performance testing tutorial [with 15 commonly used website speed testing tools] and how to achieve the full score of Google PageSpeed Insights test / 100 points two articles!

Google PageSpeed Insights

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites14

Google PageSpeed Insights

Pingdom Website Speed Test

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites15

Pingdom

conclusion


is currently free of charge for cloudflare cdn acceleration. I disable performance optimization in page rules and do not recommend enabling it. There is also a paid one that is said to greatly increase the speed, which I have never used. After the above optimization, most people should be able to open my website https://sleele.com/ within 3 seconds.

Railgun is the ultimate acceleration solution provided by Cloudflare specifically for Business and Enterprise enterprise customers. To use it, you need to upgrade the website package to Business or Enterprise, and then install the necessary software on the server and complete the configuration on Cloudflare. This is equivalent to bilateral acceleration software, which is implemented by allowing the server to establish a long-term TCP encrypted connection with Cloudflare, using the Railgun proprietary protocol instead of the HTTP protocol, which obviously reduces connection latency. In addition, it caches dynamic pages: considering that most dynamic pages contain a lot of the same HTML information, the server will only send changed content when a user requests a new page. This is equivalent to multiple Gzip compression. The

Illustration of a speed optimization scheme for using Cloudflare CDN domestic websites16

article is redirected from sleele’s blog with a slight change. List of reference articles:

Zhang GE blog uses CloudFlare CDN acceleration to share the experience and skills of

  • after enabling CDN to get users’ real IP:Cloudflare CDN real IP address (Nginx,Apache)
  • CloudFlare free CDN acceleration custom nodes-CloudFlare optional IP to speed up CDN
  • CloudFlare免费CDN加速自定义节点-CloudFlare自选IP加快CDN速度
Disclaimer: All articles on this website, unless otherwise specified or marked, are original and published on this website. Any individual or organization is prohibited from copying, stealing, collecting, or publishing the content of this site to any website, book, or other media platform without the consent of this site. If the content on this website infringes on the legitimate rights and interests of the original author, you can contact us for assistance.