Updated on 2024-11-14 GMT+08:00

Configuration Process

Background

A game website mainly serves users in the Chinese mainland. It has a large number of files such as software packages and pictures stored on OBS. As the number of users increased, game downloading and image loading became slower, especially for users who are far away from the file storage area. To address this issue, the website decided to use the CDN service to accelerate game downloads at the lowest cost and improve user experience.

Required Data

Item

Description

Example

Domain name

Domain name of the game website. If the service area of your website is Chinese mainland or global, the domain name must be licensed by the Ministry of Industry and Information Technology (MIIT) and the license has not expired, according to China's Internet Management Regulations. Otherwise, CDN cannot provide the acceleration service for the domain name.

  • For details about how to obtain a license for a domain name on Huawei Cloud, see ICP License Service.

download.game-apk1.com (licensed)

OBS bucket

The OBS bucket version is 3.0 or later, the bucket policy is public read, and static website hosting is not enabled.

obs-doc-test

Procedure

  1. Store static resources such as images and software packages of the website in the prepared OBS bucket. You can create a bucket and upload files using OBS Console, OBS Browser, or SDK. For details, see OBS documentation.
  2. Add a domain name on CDN.
    1. Log in to Huawei Cloud console. Choose Service List > Content Delivery & Edge Computing > Content Delivery Network.

      The CDN console is displayed.

    2. In the navigation pane, choose Domains.
    3. On the Domains page, click Add Domain Names.
    4. Configure the domain name and CDN acceleration information.
      • Service Area: Select Chinese mainland.
      • Domain Names: Enter download.game-apk1.com. If you add this domain name to CDN for the first time, verify its ownership.
      • Service Type: Select File download.
      • Origin Server Settings
        • Origin Protocol: Select Same as user.
        • Type: Select OBS bucket.
        • Address: Select the obs-doc-test bucket.
        • Static website hosting: Do not select this option.
        • Bucket: Select Public bucket.
        • Priority: Select Primary origin server.
        • Host Header: By default, the bucket domain name is used.
        • If you use an OBS bucket created after January 1, 2022 as the origin server and want to enable online preview, log in to the CDN console, choose Domains in the navigation pane, click the target domain name, click the Advanced Settings tab, click Edit next to HTTP Headers, and set Content-Disposition to inline. For details, see How Do I Preview Objects in OBS in a Browser Online?
        • If back-to-source by mirroring is enabled for your OBS bucket, do not select Static website hosting when adding an acceleration domain name. Otherwise, back to source does not take effect. For details, see Back to Source.
    5. Click OK.
  3. Configure a CNAME record on DNS.

    After the domain name is added, CDN automatically generates a CNAME for the domain name. The CNAME cannot be accessed directly. You must add it to your domain's DNS records. Then requests for your domain name will be redirected to CDN PoPs for acceleration. In this practice, the automatically generated CNAME is download.game-apk1.com.c.cdnhwc1.com. The CNAME configuration method varies depending on the DNS provider. In this document, DNS provided by Huawei Cloud is used as an example. For details about how to configure CNAME records on other DNS providers, see Configuring a CNAME Record.

    1. In the upper left corner of Huawei Cloud console, choose Service List > Networking > Domain Name Service.

      The DNS console is displayed.

    2. In the navigation pane, choose Public Zones.

      The public zone list is displayed.

    3. Click the domain name you want to add a record set to. In this practice, the domain name is game-apk1.com.
    4. Click game-apk1.com. On the displayed page, click Add Record Set in the upper right corner. The Add Record Set dialog box is displayed.
      Figure 1 Adding a record set
    5. Set the parameters as prompted. Use the default values for the parameters that are not listed in the following table.

      Parameter

      Description

      Example

      Name

      Domain name prefix.

      download

      Type

      Type of the record set.

      CNAME – Map one domain to another

      Line

      Resolution line. The DNS server will return the IP address of the specified line based on the source of visitors.

      You must add a Default line to ensure that the website is accessible to users of all carriers.

      Default

      TTL (s)

      Cache duration of the record set on a local DNS server. If your service address changes frequently, set TTL to a smaller value.

      5 min

      Value

      Domain name to be pointed to.

      If CDN acceleration is not enabled, the value is the bucket domain name. If CDN acceleration is enabled, the value is the CNAME generated by CDN.

      download.game-apk1.com.c.cdnhwc1.com

    6. Click OK.
  4. Check whether the CNAME record has taken effect.

    Open the Windows command line interface and run the following command:

    nslookup -qt=cname User-defined domain name bound to the bucket

    In this practice, the user-defined domain name bound to the bucket is download.game-apk1.com. If the CNAME generated by CDN is displayed, the CNAME configuration has taken effect.

  5. Configure the file download URL.

    Set the URL of the file to be downloaded in the code as follows: Domain name of the game website + Storage path of the file in the OBS bucket + File name.

    In the following example, the game website's domain name download.game-apk1.com and the android.apk file under the game/3.2.1/ folder in the obs-doc-test bucket are used. Then the file download URL is as follows:

    https://download.game-apk1.com/game/3.2.1/android.apk
  6. Verify the services.

    After the game website is redeployed, log in to the website, browse web pages, and download games.

    If images are displayed properly and the games are downloaded successfully, the acceleration configuration is successful.