After you upload objects to buckets, Object Storage Service (OSS) automatically generates URLs for the objects. You can use the URLs to access the objects. If you want to access the objects by using custom domain names, you must map the custom domain names to the buckets in which the objects are stored and add CNAME records for the custom domain names.

Prerequisites

  • A custom domain name is registered. For more information, see Register a generic domain name.
  • The Internet Content Provider (ICP) filing is complete for the domain name that you want to map to your bucket in the Chinese mainland.

    For more information about how to apply for an ICP filing, see What is an ICP filing?

Limits

  • Custom domain names cannot contain Chinese characters.
  • OSS does not impose limits on the number of domain names that can be mapped to the buckets per account.
  • Each domain name can be mapped to only one bucket, and each bucket can be mapped to up to 100 domain names.
  • If you map a custom domain name to a bucket in the OSS console, the domain name cannot contain wildcard characters. If Alibaba Cloud CDN is enabled to accelerate the retrieval of resources from an OSS bucket, you can map a custom domain name that contains wildcard characters to the bucket. However, the domain name does not appear in the OSS console.

Usage notes

You can map a custom domain name to a bucket to meet the requirements in the following scenarios:

  • To make sure that the image objects in a bucket that is created in a region in the Chinese mainland after September 23, 2019 are previewed but not downloaded when you access the objects by using a browser.
  • To make sure that the web pages of a static website that is hosted in an OSS bucket are accessed but not downloaded.

Rules for using custom domain names

For example, a public-read object named exampleobject.jpg is stored in the root directory of the bucket named examplebucket in the China (Hangzhou) region. The custom domain name www.example.com is mapped to the bucket. The URLs that are used to access the object are different before and after the custom domain name is mapped to the bucket.
  • Before the custom domain name is mapped to the bucket

    You can use the following URL that contains the default domain name of the bucket to access the exampleobject.jpg object: https://examplebucket.oss-cn-hangzhou.aliyuncs.com/exampleobject.jpg.

  • After the custom domain name is mapped to the bucket

    You can use the following URL that contains the custom domain name mapped to the bucket to access the exampleobject.jpg object: https://www.example.com/exampleobject.jpg.

    Note After you map a custom domain name to a bucket, you can preview an image object in the bucket when you access the image object. If the object cannot be previewed but can be downloaded as an attachment, the browser may not support the preview of images in specific formats. To resolve this issue, you must install a plug-in that allows you to preview images in specific formats in a browser.

Use the OSS console

  1. Map a custom domain name to a bucket.
    1. Log on to the OSS console.
    2. In the left-side navigation pane, click Buckets. On the Buckets page, click the name of the desired bucket.
    3. In the navigation tree, choose Bucket Settings > Domain Names.
    4. On the Domain Names page, click Map Custom Domain Name.
    5. In the Map Custom Domain Name panel, enter the domain name that you want to map in the Custom Domain Name field.
      Domain names that contain wildcard characters are not supported. For example, *.example.com is not supported.

      If a message that indicates a domain name conflict appears, the domain name has been mapped to another bucket. To resolve this issue, you can map another domain name to the bucket or verify the ownership of the original domain name and forcibly map the domain name to the bucket. If you verify the ownership of the original domain name and forcibly map the domain name to the bucket, the mapping between the domain name and the original bucket is removed.

  2. Add a CNAME record.
    • If the domain name is managed by your Alibaba Cloud account, perform the following steps to automatically add a CNAME record.
      1. In the Map Custom Domain Name panel, turn on Add CNAME Record Automatically.
        Important If the domain name has a CNAME record, the CNAME record is updated to the new CNAME record.
      2. Click Submit.
    • If the domain name is not managed by your Alibaba Cloud account, manually add a CNAME record.

      If the domain name is not hosted by Alibaba Cloud, you must add a CNAME record to the Domain Name System (DNS) of your DNS provider.

      The following procedure shows how to manually add a CNAME record for a domain name that is hosted by Alibaba Cloud but not managed by your Alibaba Cloud account:

      1. On the Domain Name Resolution page, find the domain name and click DNS Settings in the Actions column.
      2. On the DNS Settings page, click Add DNS Record. In the Add DNS Record panel, configure the parameters. The following table describes the parameters.
        Parameter Description
        Record Type The type of the record that you want to add. Select CNAME.
        Hostname The host record based on the prefix of the domain name.
        • To add a root domain, such as aliyun.com, enter @.
        • To add a subdomain name, enter the prefix of the second-level domain. For example, if the domain name is help.aliyun.com, enter help.
        • To map all second-level domains to the domain name of the bucket, enter *.
        DNS Request Source The DNS line that is used to resolve the domain name. To allow the system to select the optimal line, we recommend that you select Default for this parameter.
        Record Value The domain name of the bucket. The domain name of a bucket is in the BucketName.Endpoint format. For example, the public endpoint of the China (Hangzhou) region is oss-cn-hangzhou.aliyuncs.com. If you create a bucket named examplebucket in the China (Hangzhou) region, the domain name of the bucket is examplebucket.oss-cn-hangzhou.aliyuncs.com.
        TTL Select the interval at which the record is updated. Keep the default value.
        Note There is a certain delay before the TTL period takes effect.
      3. Click OK.

        A new CNAME record takes effect immediately. A modified CNAME record requires up to 72 hours to take effect.

Check whether the CNAME record takes effect

You can run the ping or lookup command to check whether a specified CNAME is in effect. If the request is redirected to *.oss-cn-*.aliyuncs.com, the CNAME is in effect.

Verify the ownership of a domain name

If the custom domain name that you want to map to a bucket is not managed by your Alibaba Cloud account or is registered with another vendor, you must verify the ownership of the domain name before you can map the domain name to the bucket.

  1. Click Obtain TXT.
    Map a custom domain name
    Note OSS randomly generates a token for the domain name, which includes the following fields: Custom Domain Name, Host Record, and Value. Record the token information.
    cname
  2. Add a TXT record to your DNS records. Enter the recorded values of the Host Record and Value fields described in Step 1 and retain the default settings of other parameters.
    For more information about how to add a CNAME record, see Manually add a CNAME record.
  3. In the Map Custom Domain Name panel, click I have added the TXT record. Continue submission.
    If your configurations are correct, OSS maps the custom domain name to the bucket.

Remove a domain name mapping

If you no longer need to use a custom domain name, you can remove the mapping between the custom domain name and the bucket.

  1. On the Buckets page, click the name of the bucket to which the custom domain is mapped. In the navigation tree, choose Bucket Settings > Domain Names.
  2. On the Domain Names page, find the custom domain name and click Manage Mapping Configurations in the Actions column.
  3. In the Manage Mapping Configurations panel, click Unbind. Then, click OK.

References