Static website hosting

Last Updated: Jun 27, 2017

As mentioned in Bind custom domain names (CNAME), 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 need to specify the names of the objects in the bucket corresponding to the homepage (index page) and error page of the website respectively.

For more information, refer to OSS Static Website Hosting.

Set website hosting

Use putBucketWebsite to set website hosting:

  1. var co = require('co');
  2. var OSS = require('ali-oss')
  3. var client = new OSS({
  4. region: '<Your region>'
  5. accessKeyId: '<Your AccessKeyId>',
  6. accessKeySecret: '<Your AccessKeySecret>',
  7. bucket: '<Your bucket name>'
  8. });
  9. co(function* () {
  10. var result = yield client.putBucketLogging('bucket-name', 'region', {
  11. index: 'index.html',
  12. error: 'error.html'
  13. });
  14. console.log(result);
  15. }).catch(function (err) {
  16. console.log(err);
  17. });

View website hosting

Use getBucketWebsite to view website hosting:

  1. var co = require('co');
  2. var OSS = require('ali-oss')
  3. var client = new OSS({
  4. region: '<Your region>'
  5. accessKeyId: '<Your AccessKeyId>',
  6. accessKeySecret: '<Your AccessKeySecret>',
  7. bucket: '<Your bucket name>'
  8. });
  9. co(function* () {
  10. var result = yield client.getBucketLogging('bucket-name', 'region');
  11. console.log(result);
  12. }).catch(function (err) {
  13. console.log(err);
  14. });

Clear website hosting

Use deleteBucketWebsite to clear website hosting:

  1. var co = require('co');
  2. var OSS = require('ali-oss')
  3. var client = new OSS({
  4. region: '<Your region>'
  5. accessKeyId: '<Your AccessKeyId>',
  6. accessKeySecret: '<Your AccessKeySecret>',
  7. bucket: '<Your bucket name>'
  8. });
  9. co(function* () {
  10. var result = yield client.deleteBucketLogging('bucket-name', 'region');
  11. console.log(result);
  12. }).catch(function (err) {
  13. console.log(err);
  14. });
Thank you! We've received your feedback.