Zero-based Play with Tengxun Cloud COS Object Storage: Static Website Hosting and Anti-theft Chain Settings
Friends often ask me: I just want to host a front-end single-page application (such as Vue/React packaged project), a personal static blog, or just want to find a place to store pictures and videos. Do I have to buy a cloud server with Nginx?
Of course not. This demand is directly on
Object Storage (COS, Cloud Object Storage)
. Not only saves the effort of maintaining the server, but also
ridiculously cheap
(Usually a month as long as a few cents of storage fees), access speed is much faster than ordinary servers.
Today, we will thoroughly get through Tengxun Cloud COS, from creating and hosting static websites to configuring anti-theft chains, and the whole process of nanny-level customs clearance.
Phase 1: Meet COS and create your first bucket
Don't be fooled by the technical word "object storage. You can think of it simply as a
A super cloud disk that will never be full and has its own network link.
. You are used to using "folder files" to manage data on your computer. In COS, files are called "objects" and root folders are called "buckets".
1. Create a bucket
Log in to the Tencent Cloud console and search for "Object Storage COS".
Click Bucket List in the left menu, and then click Create Bucket ".
Key parameter configuration (determines your wallet and security): Name: name, such as mybucket (the system will automatically add a string of numbers after it). Geography: extremely important! If your website audience is mainly domestic, give priority to "Guangzhou" or "Beijing" and other core nodes. If you plan to use with Tengxun Cloud Server (CVM), you must choose the exact same region as the server, so that they are free to transfer over the intranet. Access: If you only save private backups, select "Private". Since we are going to do static website hosting and external link map bed, we must choose "public read and private write" here ". This means that people all over the world can read (download/view) your files, but only if you have the account key can upload and modify them.
Other options (such as versioning, encryption, etc.) remain the default, and click Next all the way until the creation is complete.
Phase 2: Enable static website hosting (turn the bucket into a website)
The bucket is built, and we now turn it into an accessible website.
1. Upload your web files
Click on the bucket you just created, click on "File List" and put your static web page file (which must contain a
index.html
Home page file) directly drag and upload
Root directory
.
2. Turn on the hosting switch
In the left menu of the current bucket, find and click "Basic Configuration"-> "Static Website".
Click Edit to switch the status to Open ".
Configure the index document: Enter index.html in the Index Document column. If you
The website of has a custom 404 error page, which can be filled with 404.html in the "error document.
Click Save.
3. Test visit
After saving, the system will automatically generate an "access domain name" (usually like a https://mybucket-xxx.cos-website.ap-guangzhou.myqcloud.com) for you.
Copy this link to the browser to open, and you will find that your static web page can be accessed perfectly!
Advanced Reminder: This self-contained domain name is too long and ugly. You can bind the domain name you purchased and filed in the "Custom Domain Name" below, and open the HTTPS certificate with one click to make the website normal immediately.
The third stage: configure the anti-theft chain (to protect your wallet)
The billing of COS mainly consists of two parts:
Storage capacity
and
Downstream traffic
. The storage fee is very cheap, but if your website is on fire, or the pictures and videos you put in it are stolen by others and hung directly on their website (commonly known as "theft chain"), every time others refresh the web page, they will deduct the real money and silver in your tengxunyun account.
In order to prevent bankruptcy caused by others "stealing traffic", we must configure
Hotlink Protection
.
1. The working principle of anti-theft chain
When someone visits a web page, the browser will automatically bring a name when requesting pictures and JS files in the web page.
Referrer
The request header tells the server: "Which website am I from".
The anti-theft chain is checked by this.
Referrer
. If you find that it is not a request from your own website, refuse it directly.
2. Tengxun Cloud COS Configuration Steps
In the menu on the left side of the bucket, click Security Management-> Anti-Theft Chain Settings ".
Click Edit to set the status to On ".
Anti-theft chain type: select "white list" (meaning that only the website I specify can use my files normally, and everyone else refuses).
Referer Rules: Enter your own website domain name, such as * .yourdomain.com (asterisk to allow access to all second-level domains). Enter the domain name for your local test, such as localhost or 127.0.0.1, otherwise the picture will not be displayed when you develop locally.
Contains empty Referer: select "allow": when the user directly enters the picture website address in the browser or directly opens the link in the mobile phone wechat, the request is without Referer. If you want others to see it directly, choose allow. Select "Reject": the strictest anti-theft mechanism. Even if others enter your picture link directly in the browser, they will report an error (HTTP 403) and can only be seen on your web page.
Click Save and it will take effect globally within 5 minutes.
The fourth stage: daily play COS efficient gadgets
After there are more web pages, uploading them on the web page every time is not only slow, but also easy to get stuck. Two artifacts are recommended here to allow you to manage COS like a local hard disk.
1. Official artifact: COSBrowser
Go to Tencent cloud official website to download
COSBrowser
Client (Windows/Mac supported).
The SecretId and SecretKey are required when logging in (created in "Access Management-> Access Key" in the upper right corner of the Tencent Cloud console).
After logging in, you will see an interface similar to a network disk, which supports batch upload, download and synchronization of folders, with extremely fast speed.
2. Figure bed best companion: PicGo
If you usually write Markdown notes or blog, you can download
PicGo
Software, configure the Tencent Cloud COS plug-in.
After that, you only need to take a screenshot on the computer, click the shortcut key, the picture will be automatically uploaded to COS, and a paragraph will be automatically generated on your clipboard
! [image] (https://...)
The Markdown code is simply the gospel of the creator.
Summary
Using tengxunyun COS to play with static websites and storage, the core is three steps:
Build a bucket (public read)-> transfer files and open hosting-> open a white list anti-theft chain
. Get these three steps and you have a highly available, fast and nearly free cloud website space. As long as you protect your access key (SecretKey), even if you encounter sudden large traffic, the anti-theft chain can help you keep your wallet's defense line.

