Static websites are websites in which all web pages consist only of static content, including scripts such as JavaScript code that is run on the client. You can use the static website hosting feature to host your static website in 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 the homepage returned by OSS when you use a browser to access the static website hosted on an OSS bucket.

    The object that you specify as the default homepage must be an object that is stored in the root directory of the bucket and allows anonymous access. If you have the Subfolder Homepage feature enabled, the object must also be stored in the subdirectory.

  • The default 404 page is the error page returned by OSS. When you use a browser to access the static website hosted on an OSS bucket and a 404 error occurs, OSS returns the default 404 page.

    The object that you specify as the default 404 page must be an object that is stored in the root directory of the bucket and allows anonymous access.

To allow anonymous access to the object, 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 a file 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. When you access the static website by using the custom domain name, OSS returns different responses based on your configurations of Static Pages for the bucket that hosts the website.
  • If Subfolder Homepage is disabled:
    • 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/object, OSS returns https://example.com/error.html if the object object does not exist.
  • If Subfolder Homepage is enabled:
    • When you access https://example.com/, OSS returns https://example.com/index.html.
    • When you access https://example.com/subdir/, OSS returns https://example.com/subdir/index.html.
    • When you access https://example.com/example.txt, the example.txt object is obtained.
    • When you access https://example.com/object, OSS returns one of the following responses based on your configurations for Subfolder 404 Rule because the object object does not exist:
      • If Subfolder 404 Rule is set to Redirect, which is the default value, OSS continues to check whether object/index.html exists. If object/index.html exists, OSS returns a 302 status code and redirects the request to https://example.com/object/index.html. If object/index.html does not exist, OSS returns a 404 status code and https://example.com/error.html.
      • If Subfolder 404 Rule is set to NoSuchKey, OSS returns a 404 status code and https://example.com/error.html.
      • If Subfolder 404 Rule is set to Index, OSS continues to check whether the object/index.html object exists. If the object exists, OSS returns a 200 status code and the content of this object. If the object does not exist, OSS returns https://example.com/error.html.

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

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.