You can use TOS to host a static website. First, store all contents of the website in a TOS bucket. Next, configure rules to host the website so that it can be accessed via the bucket's domain name. This topic explains how to configure these rules.
Background information
A static website consists of only static content, such as the homepage, images, and scripts. When configuring static website rules, you must specify the homepage. You can also choose to specify a default 404 page. If you do so, it will be returned when a 404 error occurs.
Prerequisites
- You have uploaded the website content to the bucket and set the object or bucket permissions to "public read". See the following documentation for instructions:
Notes
- Each bucket can only contain one static website hosting rule.
- A hosting rule will not take effect until you associate a custom domain with the bucket. For instructions, see Setting up a custom domain.
- Starting from October 18, 2022, for security and compliance reasons, if you use the bucket's default domain to access web page files with the MIME type text/html and extensions including .htm, .html, .jsp, .plg, .htx, and .stm, the response header will automatically include Content-Disposition:attachment. This means that, when you access web page files via a browser, the website will not preview the content directly. Instead, the content will be downloaded locally.
tip
If you wish to preview web pages directly, associate a custom domain with the bucket. When you access web page files using the associated custom domain, the web page content will be previewed directly. For instructions, see Setting up a custom domain. Configuration examples
The static website feature in TOS includes built-in support for subdirectory homepages. This means that when you access a URL ending with a forward slash (/) under the root domain, the default homepage of the corresponding directory is returned.
For example, if you have associated the custom domain www.test.com with a bucket, uploaded the homepage file index.html and the default 404 error file error.html to the bucket, and also uploaded the homepage file index.html to the subdirectory /subdir, the access rules are as follows:
Steps
- In the left navigation pane, click Buckets. In the Buckets list, click the bucket you want to manage.
- In the left navigation pane, select Basic configurations > Static website.
- On the Static website page, click Set default page rule.
- In the box that appears, set the following parameters and click Create.