Static website hosting best practices

Updated at:

This topic explains how to build a static website with static website hosting.

Step 1: Activate EMAS

  1. Log in to the Alibaba Cloud console.

  2. Hover over the icon in the upper-left corner. Under Products & Services, open the list of products and services.

  3. In the product list, choose Development & Operations > EMAS to go to the product page.

  4. On the product page, click Activate Now.

Step 2: Create a service space

To use the static website hosting feature, you must first create a service space. The resources for your static website are associated with this service space. Each service space is isolated from the others.

  1. Log in to the EMAS console and select Serverless.

  2. Click Create Service Space.

  3. On the Create Service Space page, enter the following information.

    Parameter

    Description

    Service space name

    Enter a custom name for the service space. The name must meet the following requirements:

    • Must contain only letters and digits.

    • Cannot start with a digit.

    • Must be 3 to 15 characters in length.

    Description

    Enter a brief description of the purpose of the service space.

    Billing method

    Options include subscription and pay-as-you-go.

    Note

    If you select subscription, you can enable auto-renewal.

  4. Click Create and Pay.

    After the service space is created, you can view the following information on its details page:

    On the Basic Information tab, you can view information such as the Space Name, Space Status, and billing mode.

    On the Access Information tab, you can view information such as the SpaceID, Secret, API endpoint, and file upload endpoint.

Step 3: Enable static website hosting

You must enable the static website hosting feature for a service space before its first use.

Step 4: Upload files

  1. Prepare your files. This tutorial uses the following two simple HTML files.

    • The index.html file contains:

      <html>
      <title>Index page</title>
      <body>
      <h2>Hello World!</h2>
      </body>
      </html>
    • The error.html file contains:

      <html>
      <title>Error page</title>
      <body>
      <h2>404 error</h2>
      </body>
      </html>
  2. In the left-side navigation pane of the EMAS console, choose static website hosting, and then click Upload File.image

  3. Click Direct Upload, and then select and upload the index.html and error.html files.image

Step 5: Update the website configuration

  1. In the left-side navigation pane of the EMAS console, choose static website hosting.

  2. Click Settings > Update Configuration.

  3. Modify the names of the index document and error document, and then click OK.

    更新网站配置

Step 6: Bind a custom domain

  1. In the left-side navigation pane of the EMAS console, choose static website hosting.

  2. Click Settings > Add Domain Name.

  3. Enter your custom domain, and then click OK.

    Note
    • Your custom domain must be ICP filed. Due to data synchronization delays with the ICP filing system, wait at least eight hours after completing your ICP filing before you configure the domain.

    • The domain may not appear immediately after you add it. Wait 1 to 2 minutes for the update to synchronize, and then refresh the page.

  4. At your DNS provider, add the CNAME record assigned to you. If you use Alibaba Cloud DNS, see CNAME record for instructions.

    domain

Step 7: Bind a certificate to the custom domain

  1. In the left-side navigation pane of the EMAS console, choose static website hosting.

  2. Click Settings.

  3. Select the domain to which you want to bind a certificate, and then click certificate > Bind certificate.

  4. This tutorial uses a third-party certificate. For Certificate type, select Add certificate. Enter the certificate name, certificate content, and private key, and then click OK.

    新增证书

Step 8: Access the static website

  1. In your browser's address bar, enter your custom domain to view the website's home page.

    index_page

  2. In the browser address bar, enter any non-existent path for the website, such as www.example.com/xxxxx, and the content of the error.html page will be displayed.

    404page_