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.
-
Open the ICP recordal website for the Ministry of Industry and Information Technology at https://beian.miit.gov.cn
. -
Enter the query keyword according to the instructions on the website.
-
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.
-
Register your custom domain with a domain name registrar.
-
Create a domain bucket and an optional subdomain bucket:
-
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. -
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
. -
-
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.
-
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:
Open the Route 53 console at https://console.amazonaws.cn/route53/
. -
Choose Hosted zones.
-
In the list of hosted zones, choose the name of the hosted zone that matches your domain name.
-
To create an alias record for your hosted zone, choose Create record.
-
Choose Switch to wizard.
-
Choose Simple routing, and choose Next.
-
Choose Define simple record.
-
For Record name, accept the default value.
-
For Record type, choose CNAME-Routes traffic to another domain name and to some Amazon Web Services resources.
-
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
-
Choose Define simple record.
-
-
(Optional) If you had a subdomain bucket with a redirect configured, follow steps 2–7 for the subdomain bucket.
-
Verify that your website and redirect work:
-
Access your website through your custom domain name, for example,
http://example.com.cn
. -
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 isexample.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.