Best practices: Hosting an Amazon S3 static website in China - Amazon Simple Storage Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Best practices: Hosting an Amazon S3 static website in China

Amazon Web Services offers multiple ways to host a static website. Amazon S3 uses server-side rendering to serve pre-built HTML, CSS, and JavaScript files to a web browser, which provides a solution for hosting webpages from an S3 bucket. You can host your website in an S3 bucket and link your domain name directly to it. You can also use Amazon S3 with a content delivery network (CDN), such as Amazon CloudFront, to deliver webpages. A CDN accelerates the delivery of website content to your customers, reducing latency to milliseconds.

This topic outlines the process for receiving an internet content provider (ICP) recordal and accessing your website through your custom domain name in the Amazon Web Services China (Beijing) Region and China (Ningxia) Region. To host a static website in China, Chinese regulations require you to first obtain a recordal from the ICP recordal system or an ICP license from the competent government authority. Domains without an ICP recordal or an ICP license aren't permitted to provide internet information services in China. Apart from helping you to comply with regulations, a custom domain has advantages over an S3 website endpoint. Custom domains are easier to remember than S3 website endpoints. They're also logged and indexed by search engines, which can help customers find your website.

Prerequisites

Before you can configure your custom domain to host an S3 static website in the Amazon Web Services China (Beijing) Region and China (Ningxia) Region, you must complete the following prerequisites.

Get your ICP recordals

If your domain name is publicly accessed through the servers in the Amazon Web Services China (Ningxia) Region that are operated by Ningxia Western Cloud Data Technology Co., Ltd. (NWCD), you must apply for an ICP recordal through NWCD.

If your domain name is publicly accessed through the servers in the Amazon Web Services China (Beijing) Region that are operated by Beijing Sinnet Technology Co., Ltd. (Sinnet), you must apply for your ICP filing through Sinnet.

If you apply for an ICP recordal, the review process can take 3–20 days. For more information about the ICP recordal process, including FAQs, downloads, and detailed instructions, see ICP recordal.

To confirm if a domain name has an ICP recordal

If you don’t know if you already have an ICP recordal, you can check for an existing ICP recordal on the Ministry of Industry and Information Technical website.

  1. Open the ICP recordal website for the Ministry of Industry and Information Technology at https://beian.miit.gov.cn.

  2. Enter the query keyword according to the instructions on the website.

  3. To see whether an ICP recordal has been filed for your domain name or entity, enter your information in the search box.

Configure your Amazon S3 static website

Before you map your custom domain to an S3 endpoint, you must complete the following prerequisites. If you haven't completed these prerequisites, see steps 1–10 in Tutorial: Configuring a static website using a custom domain registered with Route 53.

  1. Register your custom domain with a domain name registrar.

  2. Create a domain bucket and an optional subdomain bucket:

    1. For your domain bucket, enable static website hosting, and then upload your website content. After you enable static website hosting, your domain bucket is assigned an S3 website endpoint, for example, www.example.com.cn.s3-website.cn-north-1.amazonaws.com.cn. You will use this website endpoint to configure your Route 53 custom domain.

    2. For your subdomain bucket, under Static website hosting, configure a redirect request for an object to redirect to the website content that is uploaded to your domain bucket.

    Your domain bucket contains the files that make up your website. Your subdomain bucket reroutes requests to your domain bucket. For example, if a customer enters www.example.com.cn, your subdomain bucket will forward the request to your domain bucket: example.com.cn.

  3. Clear all four S3 Block Public Access settings. You must clear all block public access settings so that you can add a bucket policy that allows public read access to your bucket.

  4. Add a bucket policy that allows public read access to your bucket. When you add a bucket policy that grants public read access, customers can access your website content.

Configuring your custom domain with Route 53

After you receive your ICP recordals and complete the prerequisites to configure your static website in Amazon S3, you can map your custom domain name to your Amazon S3 static website and access your website through your custom domain. The following procedure uses Route 53 as the domain name manager. If you use a different domain name registrar than Route 53, you must follow similar steps with your domain name registrar to map your custom domain to your S3 website endpoint. For detailed steps, contact your domain name registrar.

To map your custom domain to your S3 website endpoint

After you complete the prerequisites to configure your static website in Amazon S3, you have a website endpoint, for example www.example.com.cn.s3-website.cn-north-1.amazonaws.com.cn (www.example.com.cn). To configure alias records for your domain and subdomain, follow these steps:

  1. Open the Route 53 console at https://console.amazonaws.cn/route53/.

  2. Choose Hosted zones.

  3. In the list of hosted zones, choose the name of the hosted zone that matches your domain name.

  4. To create an alias record for your hosted zone, choose Create record.

    The Route 53 console showing the Hosted zone details section with the Edit hosted zone button highlighted.
  5. Choose Switch to wizard.

    The Route 53 console showing the Create record page with the Switch to wizard text highlighted.
  6. Choose Simple routing, and choose Next.

  7. Choose Define simple record.

    The Route 53 console showing the Define simple record screen in the create alias record wizard.
    1. For Record name, accept the default value.

    2. For Record type, choose CNAME-Routes traffic to another domain name and to some Amazon Web Services resources.

    3. For Value/Route traffic to, choose IP address or another value, depending on the record type. In the text box, enter the S3 website endpoint: s3-website.cn-north-1.amazonaws.com.cn.

    4. Choose Define simple record.

  8. (Optional) If you had a subdomain bucket with a redirect configured, follow steps 2–7 for the subdomain bucket.

  9. Verify that your website and redirect work:

    1. Access your website through your custom domain name, for example, http://example.com.cn.

    2. If you configured a subdomain bucket, access your website through your subdomain, for example, http://www.example.com.cn.

Reconfiguring websites that are hosted in Amazon S3

If you already have a static website that's hosted in Amazon S3 and you have a domain name that already has an ICP recordal, there are four ways that you can link your domain name directly to your S3 bucket. Amazon S3 offers the following options:

  • Link your domain to your S3 bucket – If your S3 bucket name is the same as your website domain name (for example, your bucket name is example.cn and your website name is example.cn), follow the instructions provided by your domain name provider to link your domain to your S3 bucket. These instructions vary for each provider.

    You can't change an S3 bucket name after the bucket has been created. If your bucket name is different from your website domain name, you can do one of the following:

  • Purchase a new domain – You can buy a new domain with a name that is the same as your bucket name, get an ICP recordal, and then follow the steps provided by your domain name provider to link your domain name to your bucket.

  • Move your website content to a new bucket whose name is the same as the domain name – You can create a new bucket with a name that's the same as the website domain name, get an ICP recordal, and then follow the steps provided by your domain provider to link your domain to your website bucket. If your bucket name is not available, you can use Amazon CloudFront, as described in the next bullet point.

  • Use Amazon CloudFront to map a domain to a bucket name where the domain name is not the same as a bucket name – To use CloudFront to map your domain name to your bucket, do the following:

    • Follow Step 2: Create a CloudFront distribution to create a CloudFront distribution that's mapped to your bucket. For the Origin access in your origin configuration, use an origin access identity (OAI), but don't accept its default value.

    • Follow Adding an alternate domain name to add an alternate domain name to your CloudFront distribution.

    • After the CloudFront distribution is working, disable S3 static website hosting, and remove the public read access statement from your bucket policy.

Note

CloudFront won't process your requests unless you have an ICP recordal for your domain.

Accessing your website through your custom domain

After you configure your static website to use a custom domain, you must update all links to your S3 website in all locations that previously referenced the URL for your S3 website endpoint. For example, you must update your documentation pages, email newsletters, and so on, to use the new custom domain. Your custom domain will be easier for your customers to remember, and customers will be able to find your website in search engines when they use keywords in searches.