tencent cloud

Feedback

Switch bucket to custom domain

Last updated: 2024-07-05 18:50:41

    Background

    To ensure overall service security and stability, for buckets created after January 1, 2024, if the default domain of Cloud Object Storage (COS) is used to access objects, preview of any type of file and download of apk/ipa type files are not supported. For details, see Implementation Notice on Security Management of COS Bucket Domain.
    
    For buckets created after January 1, 2024, if you want to preview files directly or download apk/ipa type objects within the bucket through a browser, it is recommended to use a custom domain to access objects. Buckets created before January 1, 2024 are not affected by this change when the default domain is used for preview and download. However, for better service stability, it is recommended to prioritize using a custom domain.
    
    This document describes how to configure a custom domain for a bucket, switching from accessing the bucket's default domain to accessing a custom domain.
    

    Step 1: Registering and Filing a Domain

    First, you need to prepare a custom domain that has been filed.
    Domain registration: If you do not have a custom domain, you can purchase one at Domains.
    Domain filing: If your custom domain is to be configured for a bucket in the Chinese mainland region, it must be filed.

    Step 2: Configuring a Custom Domain for the Bucket

    1. After preparing the custom domain, log in to the COS console, go to the bucket list, and select the bucket you need to configure.
    2. Enter the bucket details page, and choose Domain Name and Transport Management > Custom Origin Server Domain.
    3. Click Add Domain, and configure the domain information:
    Domain: Enter the prepared custom domain.
    Origin Server Type: The following types are available.
    Default Origin Server: If you want to use the custom domain as the default origin server, select Default Origin Server.
    Static Website Origin Server: If you want to use the custom domain for a static website, first enable the static website feature for the bucket, and then select Static Website Origin Server.
    Global Acceleration Origin Server: If you want to use the custom domain for global acceleration, first enable the global acceleration feature for the bucket, and then select Global Acceleration Origin Server.
    4. Configure an HTTPS certificate. If you want to access using the HTTPS protocol, you need to configure a certificate for the custom domain.
    If you need to use your own certificate, paste the certificate content and private key content into the specified input boxes.
    If you are using a certificate from Tencent Cloud, you can directly select an existing Tencent Cloud certificate under the current account in the pop-up window.
    5. Upon completing the custom domain configuration, record the CNAME information (e.g., bucket-1250000000.cos.ap-beijing.myqcloud.com) for subsequent domain name resolution configuration.

    Step 3: Configuring Domain Name Resolution

    Tencent Cloud Domain

    If your domain DNS provider is Tencent Cloud, go to the DNS console to configure the CNAME resolution record.
    
    1. Go to the DNS console, find the corresponding domain, and click the Resolution button.
    2. Click Quick Add Resolution to add a resolution record for the domain.
    3. In the pop-up window, select Website Resolution, and choose Domain Name Mapping (CNAME) for the website address. Enter the CNAME information recorded in Step 2, for example, bucket-1250000000.cos.ap-beijing.myqcloud.com.
    4. It takes some time for the resolution record to take effect. You can use the dig command or check in the COS console to see whether the resolution is successfully applied. The verification methods are as follows:
    Enter the command dig mydomain.com in the command line window, and check whether the CNAME record is correctly applied. (Replace mydomain.com with your actual domain when using it.)
    
    Log in to the COS console and check the bucket's custom domain. If the domain's CNAME is not successfully applied, a corresponding prompt will appear.

    Other Vendors' Domains

    If your domain DNS provider is not Tencent Cloud, you need to go to the corresponding DNS service to configure the CNAME resolution record.

    Step 4: Accessing Your Custom Domain

    After the above steps are completed, the configuration of the custom domain is finished. Below is an explanation of how to use the custom domain to access COS.

    Viewing the Object Access Link

    1. Log in to the COS console, find the bucket with the configured custom domain, and click to enter the File List. Select an object to enter the object details. For operation instructions, see Viewing Object Information.
    2. Switch the designated domain to the custom origin server domain name. The object address and temporary link below will be correspondingly switched to the custom domain link. To access public read objects, you can use the object address (without signature). To access private read objects, you can use the temporary link (with signature).

    Switching to the Custom Domain for API Access

    For users who access COS directly via API, simply change the request Host to the custom domain when accessing.
    GET /<0bjectKey> HTTP/1.1
    Host: <BucketName-APPID>.cos.<Region>.myqcloud.com # Replace with the user's custom domain.
    Date: GMT Date
    Authorization: Auth String

    Switching to the Custom Domain for SDK Access

    For users using the SDK, simply set the domain parameter to the custom domain when initializing the client. Taking the Python SDK as an example, the code example is as follows.
    domain = 'user-define.example.com' # User's custom domain
    config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Domain=domain, Scheme=scheme)
    client = CosS3Client(config)
    For code examples of switching to a custom domain in COS SDKs of various languages, refer to the following documentation:
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support