Hosting static website with AWS S3 and Route 53

我的梦境 提交于 2019-12-05 05:29:22

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11711781/hosting-static-website-with-aws-s3-and-route-53

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!