Updated on 2023-12-13 GMT+08:00

Configuration Process

Background

A game website has stored a large number of files such as software packages and pictures on OBS. As the number of users increases, game downloading and image loading become 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 does not accelerate the domain name.

download.game-apk1.com

OBS bucket

OBS bucket whose version is 3.0 or later.

obs-doc-test

Prerequisites

Static content, such as images and software packages, has been stored in an OBS bucket.

  • You can create a bucket and upload files to the bucket using OBS Console, OBS Browser, or SDK. For details, see OBS Documentation.
  • 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 Header, and set Content-Disposition to inline. For details, see How Do I Preview Objects in OBS Through a Browser?
  • 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.

Procedure

  1. Add a domain name on CDN.
    1. Log in to the 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 Name.
    4. Configure the domain name and CDN acceleration information.
      • Service Area: Select a service area.
      • Domain Name: Enter the domain name of the game website, for example, download.game-apk1.com.
      • Service Type: Select a service type based on the application scenario.
      • Origin Protocol: Select a protocol for origin pulls.
      • Origin Server Settings
        • Type: Select OBS bucket and select the domain name of an OBS bucket under your account or customize an OBS bucket domain name.
        • Static website hosting: Select this checkbox if static website hosting has been enabled for the OBS bucket.
        • Bucket: Select Public bucket or Private bucket based on the bucket policy.
        • Priority: primary or secondary origin server.
        • Host Header: The default value is the bucket domain name.

        To use a custom OBS private bucket as the origin server, configure a policy for the private bucket. For details, see Configuring a Policy for a Custom OBS Private Bucket.

    5. Click OK.
  2. Configure a CNAME record on DNS.

    After the domain name is added, CDN automatically generates a CNAME record for the domain name. The CNAME record cannot be accessed directly. You must add the CNAME record to your domain's DNS records. Then requests for your domain name will be redirected to CDN PoPs for acceleration. In this example, the automatically generated CNAME record 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. Log in to the 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 example, 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.

    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.

      The default value is 300, which is, 5 minutes.

      Value

      Domain name alias

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

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

    6. Click OK.
    7. 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 example, the user-defined domain name bound to the bucket is download.game-apk1.com. If the CNAME record generated by CDN is displayed, the CNAME configuration has taken effect.

  3. Enable OBS authorization on CDN. (Skip this step for public read or public read/write OBS buckets.)

    If your OBS bucket is a private bucket, you must enable OBS authorization on the CDN console so that CDN can pull data from OBS. For details, see OBS Authorization.

    • If your private bucket contains resources that you do not want to make public, move the resources to another private bucket.
  4. 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
  5. 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.