简体   繁体   中英

Hosting static website with AWS S3 and Route 53

Let's say I currently have website www.a.com (entirely static) on a dedicated server and I want to switch to AWS.

So far I did the following: Create bucket www.a.com, give proper permission to make it web (visible for public) and uploaded all files. Obtain http://www.a.com.s3-website-eu-west-1.amazonaws.com .

I created Hosted Zone in AWS Route 53 and automatically got two Record Sets, NS and SOA. Next, I added a CNAME for *.a.com. with value http://www.a.com.s3-website-eu-west-1.amazonaws.com

Question is now, what do I add for an A record? I don't have an IP. (As a cause of not having an A record, www.a.com works, but a.com does not work).

Can I use my dedicated server somehow to keep serving email? How should I setup MX given I have a WHM/cPanel server?

Thanks.

First, I would recommend adding an additional bucket called a.com and working off of that, don't delete www.a.com though, you'll later add a CNAME to that so www.a.com redirects to a.com in the browser.

Now that you've created the a.com bucket, go to Properties > Static Website Hosting > Enable Website Hosting > enter index.html and upload a file with that name to your bucket.

Then go Properties > Permissions > Edit Bucket Policy > Paste the code below:

{
  "Version":"2008-10-17",
  "Statement":[{
    "Sid":"PublicReadForGetBucketObjects",
        "Effect":"Allow",
      "Principal": {
            "AWS": "*"
         },
      "Action":["s3:GetObject"],
      "Resource":["arn:aws:s3:::example-bucket/*"
      ]
    }
  ]
}

Change {example-bucket} to {a.com} and save.

Now go to Route53 > Select your domain > Go to record sets > create record set

Make sure 'Type' is set to 'A' and then select 'Yes' next to 'Alias'. Click into the Alias Target area and under S3 websites you should now see a.com. Select it and then at the bottom choose 'Create record set'.

You're done.

This is a commonly encountered restriction when hosting a static site on S3. You have a few options.

  • Determine the IP addresses used by your S3 bucket using dig , nslookup or similar tools. This will work, but it's likely to eventually break as Amazon shuffles around their IPs.
  • Use a DNS provider other than Route53 that provides a "naked redirect" service. The DNS provider will do a HTTP 301 redirect to your "www" record when someone accesses your root.
  • Host a really simple website on your own server/EC2 instance that issues that same HTTP 301 redirect.

Edit: As of Dec 27, 2012 S3 now supports a way to do this without all the above mentioned workarounds. Check out the AWS blog about root website hosting from S3 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM