You can use the PutBucketWebsite API of OSS to set your bucket to the static website hosting mode and access the static website from the bucket endpoint.

Note For more information about the PutBucketWebsite API, see PutBucketWebsite.

If your selected bucket is located in China (Hangzhou), after the configuration takes effect, the domain of the static website is as follows:

http://<Bucket>.oss-cn-hangzhou.aliyuncs.com/
Note When you use the default endpoint to access a Webpage object in OSS in Mainland China or Hong Kong through the Internet, Content-Disposition:'attachment=filename;' is automatically added to the response header. That is, when you use a browser to access a Webpage object, the object is downloaded as an attachment. If you use a custom domain to access OSS, the information is not added to the response header. For more information about how to use a custom domain to access OSS, see Bind a custom domain.

OSS provides the following features to help you manage static websites hosted in OSS more easily:

  • Index document support

    The index document is the default index page (such as index.html) that OSS returns when a user directly accesses the root domain of a static website. If you set a bucket to the static website hosting mode, you must specify the index document.

  • Error document support

    The error document is an error page that OSS returns if an HTTP 4XX error (such as 404 NOT FOUND) occurs when a user accesses a static website. By specifying the error document, you can provide your users with appropriate error messages.

For example, you set the index document to index.html, the error document to error.html, the bucket name to oss-sample, and the endpoint to oss-cn-hangzhou.aliyuncs.com.

  • When a user accesses http://oss-sample.oss-cn-hangzhou.aliyuncs.com/ and http://oss-sample.oss-cn-hangzhou.aliyuncs.com/directory/, the user actually accesses http://oss-sample.oss-cn-hangzhou.aliyuncs.com/index.html.

  • If the object does not exist when a user accesses http://oss-sample.oss-cn-hangzhou.aliyuncs.com/object, OSS returns http://oss-sample.oss-cn-hangzhou.aliyuncs.com/error.html.

Operating methods

Operating method Description
Console Web application, which is intuitive and easy to use
Java SDK SDK demos in various languages
Python SDK
PHP SDK
Go SDK
C SDK
.NET SDK
Node.js SDK
Ruby SDK

Detail analysis

  • On a static website, all Webpages are composed of static content, including scripts such as JavaScript that are run on the client. OSS does not support content that needs to be processed by the server, such as PHP, JSP, and ASP.NET content.
  • To access a bucket-based static website by using a custom domain, you can bind a custom domain.
  • When you set a bucket to the static website hosting mode:
    • The index document is required and the error document is optional.
    • The specified index document and error document must be objects in the bucket.
    Note If you use an Archive bucket, you must specify Standard objects or restored Archive objects as the index document and error document. Otherwise, the static website cannot be accessed.
  • After you set a bucket to the static website hosting mode:
    • OSS returns the index document for anonymous access to the root domain of the static website, and returns the result of the GetBucket operation for authorized access to the root domain of the static website.
    • OSS returns a specified object to users who access the root domain of a static website or an object that does not exist in OSS. OSS also charges a fee for such requests and the generated traffic.

Reference