大网数据广告活动
服务器运维问答

AWS - Redirect Naked Domain to WWW

· 52CE 我爱测

I'm hosting a static website on AWS and want the naked domain to redirect to www. For example, if the user enters example.com I want it to show as www.example.com. I found this question which is the exact same question as mine, b…

问题原文

原帖链接 · eric · CC BY-SA 3.0

I'm hosting a static website on AWS and want the naked domain to redirect to www. For example, if the user enters example.com I want it to show as www.example.com.

I found this question which is the exact same question as mine, but I want to ask a few more specifics before I take my site offline to change this.

I followed the AWS tutorial to deploy a static website. So if I want my root bucket to redirect to the www bucket, I will deploy the HTML/CSS/JS files to the www bucket and then set the root bucket to redirect?

Lastly, when I set the bucket policy. This is how the tutorial explained to do it for the root domain:

{
  "Version":"2012-10-17",
  "Statement": [{
    "Sid": "Allow Public Access to All Objects",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::example.com/*"
  }
 ]
}

I wouldn't need this anymore and instead would put this on the www bucket. However, do I change the Resource to www.example.com/*?

{
  "Version":"2012-10-17",
  "Statement": [{
    "Sid": "Allow Public Access to All Objects",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::www.example.com/*"
  }
 ]
}

So it would be

"Resource": "arn:aws:s3:::www.example.com/*"

Is that how you would set it up?

已采纳解答

原帖链接 · Matt Houser · CC BY-SA 3.0

Create your www.example.com bucket and set it up for hosting a static website. Apply your policy (pasted here for completion):

{
  "Version":"2012-10-17",
  "Statement": [{
    "Sid": "Allow Public Access to All Objects",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::www.example.com/*"
  }
 ]
}

The Resource property is updated with the current bucket.

Once that's in place, deploy your website to this bucket. Update your Route 53 records to point www.example.com to this bucket. You should then test www.example.com to ensure it's working. If not, fix it. Only when it's working should you continue.

Once the www.example.com is working, then you would modify your example.com bucket to simply redirect to www.example.com. No need to modify your Route 53 records since it's already pointing to your example.com bucket.

Once this is done, your browser should hit example.com and then be redirected to www.example.com.

When you're all done, you can delete all the objects from your example.com bucket since they're not being accessed anymore. You can also remove any custom permissions/policies on that bucket.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-31)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。