After you upload an object to a bucket in OSS, a URL is generated for the object. You can use this URL to access the object in the bucket. To access an uploaded object by using a custom domain name, you must bind the custom domain name to the bucket that contains the object and add a CNAME record that points to the public endpoint of the bucket.

Note A maximum of 100 domain names can be bound to each bucket. One domain name can be bound to only one bucket. OSS does not impose limits on the number of domain names.

Common concepts

Before you bind a custom domain name to a bucket, you must understand the following concepts:
  • Custom domain name: the domain name that you purchase from a Domain Name System (DNS) service provider.
  • OSS endpoint or bucket endpoint: the domain name that OSS assigns to your bucket. You can use this domain name to access resources in your bucket. To access an OSS bucket by using a custom domain name, you must bind the domain name to the OSS endpoint and add a CNAME record to DNS.
  • Accelerate endpoint: the transfer acceleration-based domain name that OSS assigns to your bucket after transfer acceleration is enabled. You can use accelerate endpoints to accelerate the access to resources in your bucket. Accelerate endpoints are especially suitable when you access data over long distance from different countries or continents. For more information, see Transfer acceleration.

Scenarios and processes

For example, User A has a website by using the img.example.com domain name and the website contains an image by using the http://img.example.com/logo.png URL. To simplify management, User A wants to redirect all requests for the image to OSS without modifying the code or the image URL. In this case, User A can bind a custom domain name to the image object. Process:

  1. User A creates a bucket named example-img in OSS and uploads the image to the bucket.
  2. User A binds the img.example.com custom domain name to the example-img bucket in the OSS console.
  3. After img.example.com is bound to example-img, OSS maps the custom domain name to the bucket.
  4. User A adds a CNAME rule on the DNS server to map img.example.com to example-img.oss-cn-hangzhou.aliyuncs.com, which is the OSS endpoint of example-img.
  5. After OSS receives the http://img.example.com/logo.png request, OSS redirects the request to example-img based on the mapping relationship between img.example.com and example-img. Users who attempt to access the image URL http://img.example.com/logo.png are redirected to http://example-img.oss-cn-hangzhou.aliyuncs.com/logo.png.

The following table compares how the object is accessed before and after the custom domain name is bound.

Before the custom domain name is bound After the custom domain name is bound
  1. An access request for http://img.example.com/logo.png is sent.
  2. DNS resolves the request to the IP address of the source server.
  3. The source server returns the logo.png image to the requester.
  1. An access request for http://img.example.com/logo.png is sent.
  2. DNS resolves the request to the OSS endpoint example-img.oss-cn-hangzhou.aliyuncs.com.
  3. The example-img OSS bucket returns the logo.png image to the requester.

Implementation modes

Implementation mode Description
Console A user-friendly and intuitive web application
PHP SDK SDK demos for various programming languages
Node.js SDK
Browser.js SDK
Ruby SDK

References