edit-icon download-icon

CNAME

Last Updated: Nov 06, 2017

OSS supports binding custom domain names to OSS to seamlessly migrate data storage to the 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. After 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 the OSS service and create a bucket

  • Bind img.my-domain.com to the created bucket

  • Upload images to the created bucket in OSS

  • 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)

Follow the preceding steps to use the original address http://img.my-domain.com/xx.jpg to access images on OSS.

For more information, see Bind custom domain names (CNAME).

SDK supports the use of a CNAME as the endpoint. To do this, set the :cname parameter to true. For example:

  1. require 'aliyun/oss'
  2. include Aliyun::OSS
  3. client = Client.new(
  4. endpoint: 'ENDPOINT',
  5. access_key_id: 'ACCESS_KEY_ID',
  6. access_key_secret: 'ACCESS_KEY_SECRET',
  7. cname: true)
  8. bucket = client.get_bucket('my-bucket')

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

Thank you! We've received your feedback.