Static websites are websites in which all web pages consist only of static content, including scripts such as JavaScript code running on the client. You can use the static website hosting feature to host your static website on an Object Storage Service (OSS) bucket and use the endpoint of the bucket to access the website.

Note For more information about the API operation used to configure static website hosting, see PutBucketWebsite.

Usage notes

When you configure static website hosting, you must specify the default homepage and the default 404 page for the website.
  • The default homepage is displayed when you use a browser to access the static website hosted on an OSS bucket. The default homepage functions similar to the index.html file of a website.

    The object that you specify as the default homepage must be an object that is stored in the root directory of the bucket and can be accessed by anonymous access. Only objects in the HTML format are supported.

  • The default 404 page is the error page returned by OSS when a 404 error occurs when you access objects in a bucket by using a browser.

    The object that you specify as the default 404 page must be an object within the root directory of the bucket that allows anonymous access. The following object formats are supported: HTML, JPG, PNG, BMP, and WebP.

To access an object by using anonymous users, you must set the access control list (ACL) of the object that is specified as the default homepage or default 404 page to public-read. For more information about how to set object ACLs, see Configure ACL for objects.

When you access a static website hosted on a bucket by using the default endpoint of the bucket, the website is downloaded as an object to your local computer. To preview a static website hosted on a bucket, you must map a custom domain name to the bucket and access the website by using the custom domain name. For more information about how to map a custom domain name to a bucket, see Map custom domain names.

Configurations

After you host a static website on a bucket, you must upload an object whose name is the same as that of the default homepage, such as index.html, to the bucket. If the bucket contains a directory such as subdir/, you must upload the object named index.html to subdir/. In addition, you must upload an object whose name is the same as that of the default 404 page, such as error.html, to the bucket. The following structure shows the objects and directories in the sample bucket:
Bucket
 ├── index.html
 ├── error.html
 ├── example.txt
 └── subdir/
      └── index.html
In this example, the custom domain name example.com is mapped to the bucket, the default homepage of the static website hosted on the bucket is index.html, and the default 404 page of the website is error.html. The following rules apply when you access the static website by using the custom domain name:
  • When you access https://example.com/ and https://example.com/subdir/, OSS returns https://example.com/index.html.
  • When you access https://example.com/example.txt, the example.txt object can be obtained if the object exists.
  • When you access https://example.com/example.txt, OSS returns https://example.com/error.html if the example.txt object does not exist.

Implementation methods

Implementation method Description
Console A user-friendly and intuitive web application
OSS SDK for Java SDK demos for various programming languages
OSS SDK for Python
OSS SDK for PHP
OSS SDK for Go
OSS SDK for C
OSS SDK for .NET
OSS SDK for Node.js
OSS SDK for Ruby

Reference

You can host a static website on an OSS bucket and allow users to access the website by using the custom domain name that is mapped to the bucket, such as example.com. For more information about how to host a static website on a bucket, see Tutorial: Configure static website hosting by using a custom domain name.