edit-icon download-icon

Static website hosting

Last Updated: Nov 06, 2017

In CNAME, we mentioned that the OSS allows you to direct your domain name to the OSS service address. In this way, the OSS bucket is accessed when you access your website. You must specify the names of the objects in the bucket corresponding to the homepage (index) and error page (error) of the website respectively.

For more information, see Static website hosting.

Set website hosting

The following code uses Bucket#website= to configure hosted pages:

  1. require 'aliyun/oss'
  2. client = Aliyun::OSS::Client.new(
  3. endpoint: 'endpoint',
  4. access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')
  5. bucket = client.get_bucket('my-bucket')
  6. bucket.website = BucketWebsite.new(index: 'index.html', error: 'error.html')

View website hosting

The following code uses Bucket#website to display hosted pages:

  1. require 'aliyun/oss'
  2. client = Aliyun::OSS::Client.new(
  3. endpoint: 'endpoint',
  4. access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')
  5. bucket = client.get_bucket('my-bucket')
  6. web = bucket.website
  7. puts web.to_s

Clear website hosting

The following code uses Bucket#website= to clear hosted pages:

  1. require 'aliyun/oss'
  2. client = Aliyun::OSS::Client.new(
  3. endpoint: 'endpoint',
  4. access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')
  5. bucket = client.get_bucket('my-bucket')
  6. bucket.website = BucketWebsite.new(enable: false)
Thank you! We've received your feedback.