My previous post on my blog mentioned thatChanged the personalized domain nameDue to the inability to record in zhang.ge, the server has to be migrated to foreign countries. By the way, the blog currently uses AWS's lightsail, which coordinates Tokyo, and the configuration is shown in the figure below:
A little more than $10 per month, and about 80 soft sister coins are converted, which is more cost-effective than the vast majority of domestic cloud servers configured in Hong Kong or overseas.It will be cheaper if you choose the first two packages.
However, friends who have really used foreign servers know that under the influence of "Kung Fu King", foreign servers will twitch in the evening.So consider building a layerCDNTo alleviate, and may also help carry malicious attacks.
What is CloudFlare (hereinafter referred to as CF) and how to set it will not be repeated here. You can search for the detailed use tutorial of CF online, and many netizens and bloggers have shared the tutorial with pictures and texts.The following is mainly to record and share some experiences or skills found by Zhang Ge's blog in the use of CF, hoping to provide some references for students who are using or will use CF.
1、 CNAME access mode
Those who have known about CF may know that the CF free package can only be accessed through NS.This method is not flexible enough and takes effect slowly. The most important problem is that it is impossible to manually resolve the CF node IP address.
It is also very simple to realize the CNAME access mode of CF. Here we can use a third-party CF management platform. For example, Zhang Ge Blog uses:BNXB。These platforms operate domain names through CF's API, so they have localized all CF's functional options, greatly reducing the threshold for domestic users!Of course, the most attractive thing is that I can use CNAME access.
Access is very simple. You can perform access operations on the platform by registering the platform account and referring to the prompt to bind the CF API account.Here you can directly select the CNAME access method:
If you find it hard to understand the description and do not know how to fill it in, you can actually select the DNS access method first, and then convert it to the CNAME method again on the platform.This platform can switch between CNAME and DNS access modes at any time:
After the access is completed, we can refer to some experiences shared by previous people on the network to optimize the configuration (all in Chinese, I will not introduce them here), and the platform will provide a CNAME record available:
At this time, we can resolve the previous @ or WWW records to this cname in the original domain name management (such as dnspod, HiChina, etc.), and then complete the CF access.
2、 Specify node resolution
As shown at the end of Figure 6 above, after accessing the CF, the CF will assign an entry IP to the domain name, usually from Los Angeles, West America.This IP is actually the AnyCast technology. When users access it, they will allocate a real node IP nearby to speed up access.Therefore, the IP detected by the ping tool is only the AnyCast entry IP, which does not show the actual node IP address.
However, the method to view the real node IP is also very simple. Each CF node has a trace interface, and the access method is: http://{Node IP/domain name}/cdn cgi/trace.For example, to view the real node address of Zhang Ge's blog, visithttps://zhang.ge/cdn-cgi/trace。
Through actual measurement, it is found that at present, domestic users will visit the US West node by default, and only the mobile and education network will visit the Hong Kong node.Therefore, the effect of domestic use of CF is still not optimistic.In this way, there will be some students' imaginations. Since I can find the real nodes, can I resolve to some fast nodes?For example, Hong Kong node.The answer is yes!!
With the above CNAME access prerequisites, we can resolve to the node IP anywhere in the domain name resolution.On the contrary, using NS access can not be so arbitrary.
The specific node IP of CF will not be announced here. If you are interested, go to Google and Baidu to search.
As a result, the two major players, China Telecom and China Unicom, were originally traveling slowly in the West, but now they can go to two relatively high-speed nodes, and the speed has been greatly improved!The default line uses the AnyCast entrance IP assigned by CF by default. First, the mobile operator users can use the Hong Kong line, and second, it is for the sake of bottom line.Speaking of the bottom line, I have to share another technique for using dnspod - D monitoring:
As shown in the figure, the D monitoring function of dnspod can detect whether the site is available. If not, it can automatically switch to the available IP.So in Figure 7, I set two IPs for both Telecom and Unicom (two free packages at most).In other words, when D monitoring finds that the CF node specified manually is down, it can automatically switch to the other two IPs (including the default AnyCast IP), which adds another layer of security:
3、 Force Cache Configuration
When I access CF, I find that although I set cache in cache and other configurations, the page is not cachedCDNNode.Finally, through the help document on the official website, it is found that CF does not cache html pages by default(Document address), and you need to set custom Page Rules, which is exactly the same as Baidu Cloud Acceleration's custom rules!Therefore, Baidu Cloud Acceleration is actually designed by "learning from" CF.
Just like Baidu Cloud Acceleration (or Baidu Cloud Acceleration is the same as CF), the free package can only set three rules, so if we are unwilling to spend money, we can only set it as shown in the figure: except that the background and comment pages are not cached, everything else is cached.As shown in the figure, there is another key point,Edge Cache TTLThis option must be set, otherwise it will not be cached!
Although it is somewhat extensive, it is acceptable for personal blogs. It may not be satisfied unless some special pages are also required not to cache.Of course, if you really need more rules, you can also spend 5 dollars/month to buy 5 additional rules:
In addition, I can see from the CF help document that Page Rules can actually be configured according to cookies. I didn't find it at that time, but it should be a paid version.It is unknown whether the five rules for purchasing for $5 can be configured more flexibly through cookies.The description is as follows:
How do you specify cookie names for Bypass Cache Cookie or Cache on Cookie? Note that Bypass Cache on Cookie is available only on Business and Enterprise plans & Cache on Cookie is Enterprise only. You can specify multiple cookie names by using the OR “|” operator. For example, to match cookie1, cookie2, or cookie3, you would write: cookie1|cookie2|cookie3. You can also use the wildcard “.*” operator, i.e. cookie1.*.
After using CDN, many friends may be troubled by caching, such as content updates, but the foreground can't see the latest content because of the CDN cache, which can be described as happy caching, boring caching.Therefore, every time I use a new CDN, I will write some supporting cache auto cleaning code (I have never used it, and naturally I won't spend time researching it~~), such as sharing before:
This time, it is no exception.And CF obviously has a more mature API interface. When I was going to roll it up, I found a new continent!In fact, CF has a dedicated WordPress plug-in called Cloudflare.We just need to search and install the background plug-in interface:
After installation, log in to the CF account in the plug-in setting interface to get a simple version of the CF control background:
Of course, these functions can be configured on official or third-party platforms, which can only be said to be icing on the cake.What we are most concerned about is that the CDN cache can be automatically deleted when the content is updated. Does the plug-in support it?The answer is yes!
In this way, I don't need to read the code, and you don't need to toss the code!It's really refreshing!
5、 Please look forward to
So much for the moment. If I find more practical CF configuration skills later, I will continue to update them to this article!
Can the blogger say what the theme is?It's like mine. I don't know if it's the same person
Buddhist software2021-6-25 · 11:58
Why can I completely overwrite the source station IP after adding a CDN before, but now there are still more than a dozen nodes not covered after deleting and re adding
Please let me know how to cache the reviewers' cookies on the comment page after using cloudflare to enable caching, how to remove them, and whether to give a tutorial