Configuring Static Website Hosting

This section describes how to configure static website hosting for buckets and use bucket domain names to access static websites.

Prerequisites

All of the website files required by the static website have been uploaded to the specified bucket.
NOTICE:

To ensure that a hosted static website can be accessed by all users, set Read for the bucket storing static website files to anonymous users. Then set anonymous users to be able to access static website files in the bucket in bucket policies, ensuring that the users have sufficient access permissions for desired objects. The configuration of static website hosting takes effect within two minutes after the configuration.

Procedure

  1. Log in to OBS Console.
  2. In the bucket list, click the target bucket to go to the Summary page.
  3. Configure the following bucket policy so that all objects in the bucket can be accessed publicly.

    1. Choose Permission > Bucket Policy.
    2. Click the Public Read card to allow all objects in the bucket to be accessible publicly, as shown in Figure 1.
      Figure 1 Configuring the public read permission

  4. In the navigation tree on the left, click Static Website Hosting.
  5. Click the Static Website Hosting card and select Use this bucket to host a website, as shown in Figure 2.

    Figure 2 Static Website Hosting

  6. Set the values of Default Home Page and Default 404 Error Page.

    • Default Home Page: specifies the default homepage of the static website. When OBS Console is used to configure static website hosting, only HTML web pages are supported.When APIs or SDKs are used to configure static website hosting, OBS does not have such a restriction but the Content-Type of objects must be specified.

      OBS only allows files such as index.html in the root directory of a bucket to function as the default homepage. That is to say, do not set the default homepage with a multi-level directory structure (for example, /page/index.html).

    • Default 404 Error Page: specifies the error page returned when an error occurs during static website access. When OBS Console is used to configure static website hosting, only HTML web pages are supported.When APIs or SDKs are used to configure static website hosting, OBS does not have such a restriction but the Content-Type of objects must be specified.

  7. Optional: In Redirection Rule, configure redirection rules.

    Requests that comply with the redirection rules are redirected to the specific host or page.

    Redirection Rule is compiled in the JSON or XML format. Each rule contains a Condition and a Redirect, as shown in the following example:

    [
        {
            "Condition": {
                "KeyPrefixEquals": "folder1/"
            }, 
            "Redirect": {
                "HostName": "www.example.com"
            }
        }, 
        {
            "Condition": {
                "KeyPrefixEquals": "folder2/"
            }, 
            "Redirect": {
                "ReplaceKeyPrefixWith": "folder3/"
            }
        }
    ]

    In the previous template, there are two redirection rules:

    • Automatically redirects requests prefixed with folder1/ to host www.example.com.
    • Automatically redirects requests prefixed with folder2/ to an object prefixed with folder3/. For example, if object folder2/work.txt on OBS is renamed folder3/work.txt and the redirection rules are enabled, access requests to folder2/work.txt will be automatically directed to folder3/work.txt.

  8. Click OK.

    After the static website hosting settings take effect on OBS, you can use the following domain names to access the static website. If you successfully access the website using the following domain names, static website hosting is successfully configured.

    https://bucketname.OBS static website hosting domain name
    http://bucketname.OBS static website hosting domain name

Follow-up Procedure

You can select Disable static website hosting to disable static website hosting when needed.

Registration