Static websites are websites where 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 in an 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 in OSS. The default homepage functions similar to index.html.

    The object that you specify as the default homepage must be an object within the root directory of the bucket that allows 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 the 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.

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

Configuration examples

The following figure provides an example of the structure of objects in a bucket:
Bucket
 ├── index.html
 ├── error.html
 ├── example.txt
 └── subdir/
      └── index.html
The custom domain name example.com is bound to the bucket, the default homepage of the configured static website is index.html, and the default 404 page 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 is obtained.
  • 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
Java SDK SDK demos for various programming languages
Python SDK
PHP SDK
Go SDK
C SDK
.NET SDK
Node.js SDK
Ruby SDK

References

Tutorial: Configure static website hosting by using a custom domain name