edit-icon download-icon

CNAME

Last Updated: Nov 02, 2017

OSS allows you to bind custom domain names (CNAME) to the OSS bucket This enables you to seamlessly migrate data to the OSS. For example, your domain name is my-domain.com, and most likely all your images are in http://img.my-domain.com/x.jpg format. After you migrate the image storage to OSS, you can still access the images by binding your custom domain name to OSS. The steps are as follows:

  1. Activate the OSS service and create a bucket.

  2. 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).

  3. In the Console of the Official Website or use the SDK to bind img.my-domain.com to the created bucket.

  4. Upload images to the created bucket in OSS.

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

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

Add a CNAME

You can bind a CNAME for the bucket using the addBucketCname interface:

  1. <?php
  2. use OSS\OssClient;
  3. $client = new OssClient(
  4. '<Your AccessKeyId>',
  5. '<Your AccessKeySecret>',
  6. '<Your Endpoint>');
  7. $client->addBucketCname('bucket name', 'img.my-domain.com');

Delete a CNAME

You can unbind a CNAME using the deleteBucketCname interface:

  1. <?php
  2. use OSS\OssClient;
  3. $client = new OssClient(
  4. '<Your AccessKeyId>',
  5. '<Your AccessKeySecret>',
  6. '<Your Endpoint>');
  7. $client->deleteBucketCname('bucket name', 'img.my-domain.com');

Get a bound CNAME

You can get the list of bound CNAME of a bucket using getBucketCname interface:

  1. <?php
  2. use OSS\OssClient;
  3. $client = new OssClient(
  4. '<Your AccessKeyId>',
  5. '<Your AccessKeySecret>',
  6. '<Your Endpoint>');
  7. $cnameConfig = $client->getBucketCname('bucket name', 'img.my-domain.com');
  8. var_dump($cnameConfig);
Thank you! We've received your feedback.