This document describes how to host an existing or new static website on COS and make it accessible to visitors through a custom domain name such as
www.example.com. The specific steps are outlined below:
- For the static website configuration to take effect, you need to use the domain name of the static website instead of the COS default domain name to access the COS origin server.
- This practice only applies to scenarios where you need a domain name in Mainland China for your business.
The following services will be used in the steps outlined below:
www.example.com. You can do so via the Tencent Cloud Domain Service.
The sample domain name
www.example.comis used in the steps outlined in this document. For your purposes, replace it with your own domain name.
Domain registration is a prerequisite for any service built on the Internet. After the domain name is registered, it needs to go through the MIIT filing procedure before your website can be accessed.
After having registered the domain name and obtained ICP filing, you need to perform the following steps on the COS console:
Please log in to the COS Console with your Tencent Cloud account and create a bucket for your website. This bucket can be used to store website content and data.
If you are using COS for the first time, you can create a bucket by accessing the Bucket List page on the left sidebar of the console and then clicking Create Bucket in the upper left-hand corner. For detailed directions, see Creating Buckets.
(1) Enable a Static Website for the bucket in the following way:
a. Log in to the COS Console, and click Bucket List on the left sidebar. Locate the bucket, and click Configuration Management under the Actions column.
b. Scroll down to the Static Website section under Basic Configuration, click Edit, and switch the Status to on. Configure the Index document field to
index.html, leaving the other fields blank for now, and then click Save.
(2) Upload your website contents to the bucket. For detailed directions, see Uploading Objects.
You can use the bucket to store any content you want to host, including text files, photos, and videos. If you haven't built your website yet, just create a file as described in this document.
For example, you can create a file with the following HTML code and upload it to the bucket. The filename of the website homepage is usually index.html. In subsequent steps, you will need to provide this file as an index document for your website.
<!DOCTYPE html> <html> <head> <title>Hello COS!</title> <meta charset="utf-8"> </head> <body> <p>Thank you for using the static website feature of  COS&.</p> <p>This is the homepage!</p> </body> </html>
After the COS static website feature is enabled, if a user accesses any first-level directory that does not point to any files, COS will first match
index.htmlin the bucket directory and then
index.htmby default. If this file does not exist, a 404 error will be returned.
We recommend that you use a custom CDN domain name so that Tencent Cloud CDN can accelerate the delivery of your static website contents for a better user experience.
(1) Log in to the COS Console, go to the Bucket List page on the left sidebar, and click the bucket that hosts your website.
(2) Click Domain Management to open the details page and then click Add Domain in the Custom CDN Acceleration Domain section to add a domain. Configure the domain as follows and then click Save.
(3) Follow the prompt above the domain list to add CDN Service Authorization.
Click OK in the pop-up window.
(4) Wait a few minutes until the domain name’s status is displayed as Online. Then, copy the CNAME and proceed to [Step 3.2](#Step 3.2).
If you registered your domain name through a third-party ISP, go to your ISP, add a CNAME record for your custom CDN domain name, and point it to the CNAME record configured above. To use Tencent Cloud DNS, follow these steps:
(1) Log in to the DNS Console, locate your domain name, and click DNS.
(2) Click Add Record.
(3) Click Save.
After completing the above steps, verify the result by entering the domain name, e.g.
www.example.com, in your browser:
http://www.example.com: Returns the index page (index.html) in the bucket named
http://www.example.com/folder/: Returns the index page (folder/index.html) under the
folderdirectory in the bucket named
http://www.example.com/test.html(a non-existing file): returns 404 error. If you want to customize the error document, you can do so in step 2 when configuring the static website, so that when an access attempt is made to a non-existing file, this error document will be displayed.
- In some cases, you may have to clear your browser's cache to see the expected result.
- For each bucket, you can configure only one error document, which can be placed in a sub-directory, such as pages/404.html.