Contents
Preface
In the previous article, I migrated the navigation page of www.tangwudi.com to cloudflare pages (see article:Home data center series uses github+cloudflare pages to build a new home for www navigation page), however, this method is not suitable for the homepage of www corresponding to my registered domain name, because when Tencent Cloud CDN uses the domestic acceleration traffic package, there will be problems when the back-to-source host points to the domain name on Cloudflare (it is not impossible to add the Tencent Cloud back-to-source IP to the whitelist on Cloudflare, but in actual experience, it is very unstable, and this approach links the domestic registered domain name with the domain name actually used abroad, which is risky).
So I had to research free static page hosting solutions in China similar to github pages and cloudflare pages. However, after looking around, I found that there was no completely free one. Gitee Pages is okay, although there are limitations on the maximum capacity and single file size, but this has no impact on me. The most annoying thing is that it requires real-name registration and is very sensitive to uploaded content (each update has to be reviewed again, and deployment is prone to failure. What if I want to study static blogs in the future?), and custom domain names and automatic deployment are charged, which sounds very troublesome. Especially after the experience of free github+cloudflare pages, my vision has been raised a lot and I can't afford it.
If there is no good free plan (which is indeed a bit extravagant in China), is there a plan that can be used with a little money? There is indeed a combination of Tencent Cloud CDN + Tencent Cloud COS, which costs 9.77 to 29.77 a year (depending on whether you have a Tencent CDN annual traffic package, like I already bought it, so it only costs 9.77), and you can get a 1-year COS storage with 10G storage space, and there are no messy restrictions. If you don’t buy Tencent Cloud’s CDN domestic package, then buying a 1-year 100g traffic package is only 20 yuan, so the total is 29.77 yuan. 29.77 yuan, you can’t lose money, you can’t be fooled, you can have a 10G space static page hosting service, which is very cost-effective. . The only threshold is that you need to register the domain name.
I just happened to have one, so I ended up choosing this option.
Configuration Process
Prerequisites: Existing domain name and completed filing
If you don't have a domain name, you need to choose a domain name supplier to buy it (you can buy it for free if you can afford it). You don't have to use Tencent Cloud's dnspod. However, you can't skip the filing step because the domain names that can be accelerated by domestic CDN suppliers must be registered domain names. For example, when Tencent Cloud CDN adds an accelerated domain name, if it is not a registered domain name, it will be displayed as follows:
Note: In fact, if you don’t have a registered domain name but still need this, you can just use github pages, cloudflare pages, etc., and you don’t need to read this article.
Tencent COS creates a storage bucket
Follow the steps in the following image to create a bucket on the Tencent Cloud Object Storage interface:
Upload web directory
Upload successful:
Because I want to publish directly through the domain name, the files need to be located in the root path, so I need to go into the uploaded folder and copy all the files out:
Then return to the upper path to paste:
After pasting is complete, delete the uploaded web page directory. The final effect is as follows:
Another question: Why is it so troublesome? Because uploading the compressed package directly and then decompressing it seems to cost money. And the file upload can only upload a single file, so I have to do this. In fact, I can use tools such as COSBrowser to upload, but I don’t have any demand for COS at present, just hosting a static homepage, so I’m too lazy to bother with these. I can try it out when there is any domestic demand in the future to do experiments.
Note: In fact, if Tencent Cloud CDN is used later, the following steps to enable the static website function do not need to be configured, because they are all Tencent products and can communicate through the "default domain name" (internal domain name). However, if a CDN other than Tencent Cloud is used, the following configuration is required, so I will still write down the steps.
Enable the static website function:
The concept of "default domain name" will be used in the next section. This default domain name is actually the requested domain name in the last step of creating a bucket. This domain name can also be seen in the following location:
CDN
There are two ways to publish bucket contents to Tencent Cloud CDN:
1. Custom CDN acceleration domain name in the bucket
2. Add domain name directly to CDN
"Content Distribution Network" - "Domain Management" - "Add Domain":
The subsequent operations are the same as the general steps of adding Tencent Cloud CDN acceleration domain name, so I will not repeat them. Finally, after adding, you need to remember the CNAME address in the red box:
The CNAME address is required when configuring domain name resolution later. However, if the domain name is hosted on Tencent Cloud dnspod, the CNAME can be automatically added as soon as it is created.
Domain name resolution
This step is simple. Just add a CNAME record in the console of the domain name provider you use, pointing to the CNAME address at the end of the previous section. Take Tencent Cloud dnspod as an example:
In this way, the access to abc.example.com will be sent to the CDN for processing.
Summarize
Using Tencent Cloud CDN + Tencent Cloud COS to host static pages has both advantages and disadvantages:
1. Advantages
- COS itself is cheap, and the largest expense is the cost of storage space itself
The standard storage capacity package costs 9.77 yuan for 10GB of space per year. What pages can't be stored in 10GB of space? If you are a new user, you can also use 50GB of space for free for 180 days. - Cooperating with Tencent CDN saves external network traffic fees
Tencent COS originally had extranet traffic fees (expensive, and because of the 2-hour delay in billing, when using COS directly to publish extranet applications, if the resources on COS are hotlinked and stolen, you may lose thousands or tens of thousands of yuan in a few hours) and read and write request fees. However, because it is used with Tencent CDN, these two fees are saved, because CDN back-to-source COS is an intranet request and is not charged, so you only need to pay the traffic fee of CDN itself, and CDN traffic fees are already paid by many people (such as me), and the price is originally low, 20 yuan for 100g a year:
Even a poor person like me bought it for self-defense for 20 yuan, so it is still quite affordable.
2. Disadvantages
- COS lacks convenient file upload and download and basic file management functions by default
Therefore, if you want to perform file operations on COS frequently, you still need to map the COS storage bucket to the local PC or use tools such as COSBrowser to manage it.
- COS cannot perform version management
It is not a big deal if the static page is rarely modified (like I just put a static page to deal with record inspection). However, if it is frequently modified, it is still very troublesome if you need to determine what content has been modified and upload selectively every time. Therefore, it is best to combine it with other continuous integration projects and let COS be used only as the final storage.
In addition, you can make some protective settings (such as anti-malicious traffic attacks) on Tencent Cloud CDN according to the characteristics of the applications you deploy. For example, I just put up a page for record inspection, so many parameters are written rigidly, after all, they are only for inspectors to see, including:
There are many other options that can be used as security protection functions, and you can set them according to your actual situation. In the domestic environment, I think it is acceptable to use such a small amount of money to achieve static page hosting function.
Later, I migrated some static sites used in China to COS. So far, all my static sites, whether they are facing overseas or domestic, are hosted on the cloud, which is really convenient. The next step is to set up a static blog, import articles in WordPress into the static blog, and then host it directly on the Internet. It is perfect as a redundant site, which is much more convenient and saves trouble than using Tencent Cloud Server as a mirror site.