This section describes how to configure static website hosting for buckets and use bucket domain names to access static websites.
All of the website files required by the static website have been uploaded to the specified bucket.
If the website files are Cold storage class, restored them first. For more information see Restoring a Cold File on OBS.
To ensure that a hosted static website can be accessed by all users, set anonymous users to be able to access static website files in the bucket. The configuration of static website hosting takes effect within two minutes after the configuration.
- In the bucket list on the OBS Console, click the target bucket to go to the Summary page.
- Optional: To ensure that a hosted static website can be accessed by all users, configure the following policy so that all static website files in the bucket can be accessed publicly.
- In the navigation tree on the left, click Objects.
- Click the target object and click Object ACL.
- In Object ACL > Public Permissions > Anonymous Users, click Edit to set an object read permission for anonymous users. This option is selected in Figure 1.
Figure 1 Setting an object read permission for anonymous users
- Click Save to save the permission setting.
If the bucket contains only static website files, configure the public read policy for the bucket so that all files in the bucket can be accessed publicly.
- Choose Permissions > Bucket Policy.
- Click the Public Read card to allow all objects in the bucket to be accessible publicly. This option is selected in Figure 2.
Figure 2 Configuring the public read permission
- In the navigation tree on the left, click Static Website Hosting.
- Click the Static Website Hosting card and select Use this bucket to host a website. Figure 3 displays this page.
Figure 3 Static Website Hosting
- 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, JPG, PNG, BMP, and WEBP files under the root directory 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.
- 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:
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/.
Table 1 Parameter description
Protocol, HostName, ReplaceKeyPrefixWit, ReplaceKeyWith, HttpRedirectCode
- 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
In some conditions, you may need to clear the browser cache before the expected results are displayed.