This topic describes how to map a custom domain name to a bucket.
Object Storage Service (OSS) allows you to map a custom domain name to an OSS bucket
based on a CNAME record. You can use this method to migrate data to OSS. For example,
you have the domain name example.com, and all of your images can be accessed by using
URLs in the following format: http://img.example.com/x.jpg
. To access your images by using original URLs after you migrate the images to an
OSS bucket, perform the following steps:
- Activate OSS and create a bucket.
- Modify the Domain Name System (DNS) configurations of the domain name. Add a CNAME record to map img.example.com to an OSS endpoint such as my-bucket.oss-cn-hangzhou.aliyuncs.com.
- Log on to the OSS console to map img.example.com to the created bucket.
- Upload an image to the OSS bucket.
You can use the original URL http://img.example.com/x.jpg
to access the image that is stored in the OSS bucket. For more information about
how to map custom domain names, see Map custom domain names.
To use your custom domain name as the endpoint of a bucket when you use OSS SDK for
Browser.js, set the value of cname
to true.
let OSS = require('ali-oss')
let client = new OSS({
endpoint: '<Your endpoint>'
accessKeyId: '<Your AccessKeyId>',
accessKeySecret: '<Your AccessKeySecret>',
cname: true
});