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 as follows:
The following services will be used in this practice:
www.example.com. You can do so via Tencent Cloud Domain Service.
The sample domain name
www.example.comis used in all steps in this document. In practice, replace it with your own domain name.
Domain name registration is a prerequisite for any service built on the internet. After you register a domain name, you need to apply for ICP filing for it before your website can be accessed. Please proceed according to your actual situation:
After completing the domain name registration and ICP filing application, you need to perform the following tasks in the COS Console to create and configure the website contents:
Please log in to the COS Console with your Tencent Cloud account and create a bucket for your website. The bucket is used to store data, so you can store your website contents in it.
If you are using COS for the first time, you can directly create a bucket by clicking Create Bucket on the overview page or using the Bucket List on the left sidebar in the console. For detailed directions, please see Creating Buckets.
1). Enable the Static Website setting of the bucket in the following way:
a. Log in to the COS Console, click Bucket List on the left sidebar, locate the created bucket, and click Configuration Management on its right.
b. Find the Static Website configuration item, click Edit, set the current status to "on", leave other settings as default for now, and click Save.
2). Upload your website contents to the created bucket. For detailed directions, please see Uploading Objects.
You can store in the bucket any contents you want to host, such as text files, photos, and videos. If you haven't built a 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 file 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 static website feature is enabled, if a user accesses the first-level directory without path to any file, COS will first match index.html in the bucket directory and then index.htm by default. If this file does not exist, a 404 error will be returned.
In order to speed up access, you are recommended to set the domain name as a custom accelerated domain name, so that you can use Tencent Cloud CDN to accelerate your static website for a better user experience.
1). Log in to the COS Console, click Bucket List on the left sidebar, and click the bucket storing the website contents.
2). In the second-level menu bar on the left, click Domain Name Management to enter the domain name management page. Click Add Domain Name in the Custom Domain Name section to enter the configurable page. Configure the following items and click Save.
4). Wait a few minutes until the domain name deployment is completed. Then, copy the corresponding CNAME record and proceed to [step 3.2](#Step 3.2).
If you registered your custom domain name through a third-party service provider, add a CNAME record for your domain name at the service provider and point it to the CNAME record in step 3.1.
After completing the above steps, verify the result by entering the domain name (
www.example.com) in a browser:
http://www.example.com: The index page (index.html) in the bucket named "example" will be returned.
http://www.example.com/test.html(a non-existing file): A 404 error will be returned. If you want to customize the error document, you can add it in step 2.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.