How to Register a Domain Name and Use It for Your Own Website

2024-11-03

Background

The frontend and backend services for the personal blog have been set up, and now it's necessary to acquire a personalized domain name and apply it to the blog site. After researching, I successfully completed this task and wrote a document to record the detailed steps.

Environment and Parameters

Currently, all services are hosted on AWS public cloud services:

  • Frontend Service: CloudFront + S3
  • Backend Service: EC2 + API Gateway
  • Domain Registration: Route 53

Operation Steps

Register a Domain

  1. Log in to the AWS Management Console
    Go to the AWS Management Console and log into your AWS account.

  2. Open the Route 53 Service
    In the console homepage, find or search for Route 53, then click to enter the service.

  3. Go to the Domain Registration Page
    In the left-hand menu, select "Registered Domains" and then click the "Register Domain" button at the top of the page.

  4. Search for a Domain
    In the search bar, enter the domain name you want to register and click the "Check" button. AWS will display whether the domain is available.

  5. Select the Domain and Add It to the Cart
    If the domain is available, select it and click "Add to Cart." Route 53 will display the price of the domain.

  6. Select Registration Duration
    Choose the number of years for registration, typically 1 year or longer.

  7. Fill in Contact Information
    Provide the necessary contact information for domain registration, including name, address, phone number, etc. This information will be used for WHOIS records.

  8. Complete the Purchase
    After confirming the cart content is correct, click "Continue" and complete the payment. AWS will charge your payment method.

  9. Wait for Registration to Complete
    Domain registration may take anywhere from a few minutes to several hours. Once completed, you can see the domain under "Registered Domains" in Route 53.

Configure the Domain

Step 1: Get the CloudFront Distribution Domain Name

  1. Log in to the AWS Management Console.
  2. Open the CloudFront Console.
  3. Find and select the CloudFront distribution you want to use.
  4. On the distribution details page, note down the "Domain Name" (e.g., dxxxxxxxxxx.cloudfront.net).

Step 2: Create a Record Set in Route 53

  1. Open the Route 53 Console.
  2. Select the domain you registered.
  3. Click "Create record."
  4. Choose the record type as either "A – IPv4 address" or "CNAME" (depending on your needs).
    • A Record: If you want the root domain (e.g., example.com) to point to CloudFront, choose "A Record" and use the Alias feature.
    • CNAME Record: If you want a subdomain (e.g., www.example.com) to point to CloudFront, choose "CNAME Record."
  5. Enter the following information:
    • Record name: For example, "www" (for www.example.com) or leave it blank to point to the root domain.
    • Value: Enter the CloudFront distribution domain name (e.g., dxxxxxxxxxx.cloudfront.net).
    • TTL: You can use the default value (e.g., 300 seconds).
  6. Click "Create records."

Step 3: Add Custom Domain Name in CloudFront (Optional)

If you want to access your custom domain via CloudFront using SSL (HTTPS), perform the following steps:

  1. Return to the CloudFront Console.
  2. Select your CloudFront distribution and click "Distribution Settings."
  3. In the "General" tab, find "Alternate Domain Names (CNAMEs)."
  4. Add your custom domain name (e.g., www.example.com).
  5. Configure the SSL certificate:
    • If you have already requested a certificate from AWS Certificate Manager (ACM), select "Custom SSL Certificate" in the SSL Certificate section and choose your certificate.
    • If not, you will need to request an SSL certificate from AWS Certificate Manager and return here to configure it. (Note: CloudFront defaults to the US-East-1 region for SSL certificates, so you must create the certificate in that region.)
  6. Click "Yes, Edit" to save the changes.

Step 4: Configure SSL Certificate (Optional, Consistent with Step 3)

  1. Get Verification Record Information
    • Log in to the AWS Management Console:
      • Go to the AWS Management Console and log into your AWS account.
    • Open AWS Certificate Manager (ACM):
      • Search for and select "Certificate Manager" in the console.
    • Find your certificate:
      • In the ACM console, locate the certificate you requested, and its status should be "Pending validation."
    • View verification information:
      • Click on your certificate to view its details.
      • Under "Domain Validation," you will find a DNS verification record, usually in the following format:
        • Name: _abcdef1234567890.yourdomain.com
        • Value: _ghijklmnop1234567890.acm-validations.aws
  2. Create DNS Records in Route 53
    • Open Route 53 Console:
      • In the AWS Console, search for and select Route 53.
    • Choose your Hosted Zone:
      • In the Route 53 console, click "Hosted zones."
      • Find and select the hosted zone for your registered domain.
    • Create a new CNAME record:
      • Click "Create record."
      • In the "Record name" field, enter the CNAME record name you obtained from ACM (e.g., _abcdef1234567890).
      • Select "CNAME" for the "Record type."
      • In the "Value" field, enter the CNAME record value you obtained from ACM (e.g., _ghijklmnop1234567890.acm-validations.aws).
      • TTL: You can use the default value (usually 300 seconds).
    • Click "Create records":
      • Check the record information and click "Create records."
  3. Wait for DNS Propagation
    • After adding the DNS record, it may take some time (from a few minutes to several hours) for it to propagate globally.
    • You can use command-line tools (such as nslookup or dig) to check if the CNAME record has been successfully added and propagated.
  4. Confirm the Verification Status
    • Return to the ACM Console:
      • Reopen the AWS Certificate Manager console.
    • Check the certificate status:
      • In the certificate list, check the status of your certificate.
      • If the DNS record is correctly set up and propagated, the certificate status should update to "Issued."
    • Example Verification Command:
      • Use a command-line tool (such as Command Prompt or Terminal) to verify the DNS record:
        • nslookup -type=CNAME _abcdef1234567890.yourdomain.com
        • Or
        • dig CNAME _abcdef1234567890.yourdomain.com
      • This will return the value you set for the CNAME record, confirming that the record has been successfully added.
    • Notes:
      • Ensure there are no typos and that the DNS record in Route 53 matches exactly what ACM provides.
      • The propagation time for DNS records may be affected by DNS cache settings.

Step 5: Wait for DNS Propagation

After changing the records, it may take some time (usually from a few minutes to a few hours) for the changes to take effect. You can use nslookup or other DNS tools to check if the domain is correctly resolving to CloudFront.

Once the above steps are completed, you should be able to access your frontend project on CloudFront via the custom domain.

Note: One easily overlooked issue I encountered is that after purchasing a domain from AWS, email verification is required. The verification email was marked as spam by Gmail and went to the trash folder. After 15 days without verification, AWS suspended the domain, so be sure to watch out for this.