edit-icon download-icon

CNAME

Last Updated: Oct 31, 2017

OSS supports binding custom domain names to OSS. This enables you to seamlessly migrate data storage to OSS. For example, your domain name is my-domain.com, and all your previous image resources are in a format similar to ‘http://img.my-domain.com/x.jpg‘. Once you migrate the image storage to OSS, you can still access the images with the original address by binding your custom domain name to OSS:

  • Activate OSS service and create a bucket.

  • Modify the DNS configuration, add a CNAME record, and direct img.my-domain.com to an endpoint of OSS (for example, my-bucket.oss-cn-hangzhou.aliyuncs.com).

  • In the Official Website Console, bind img.my-domain.com to the created bucket.

  • Upload images to the created bucket in OSS.

By following the preceding steps, you can use the original address http://img.my-domain.com/xx.jpg to access the images on OSS.

For more information on how to bind custom domain names, see Bind Custom Domain Names.

The SDK supports using a CNAME as the endpoint. Therefore, set the cname parameter to true.

For example:

  1. var co = require('co');
  2. var OSS = require('ali-oss')
  3. var client = new OSS({
  4. endpoint: '<Your endpoint>'
  5. accessKeyId: '<Your AccessKeyId>',
  6. accessKeySecret: '<Your AccessKeySecret>',
  7. cname: true
  8. });
  9. client.useBucket('my-bucket')

Note: The list_buckets interface is unavailable when a CNAME is used as the endpoint, because the custom domain name has been bound to a specific bucket.

Thank you! We've received your feedback.