Cloudfront 使用 ssl 将 www 重定向到裸域 [英] Cloudfront redirect www to naked domain with ssl

查看:34
本文介绍了Cloudfront 使用 ssl 将 www 重定向到裸域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果之前有人问过这个问题,请原谅我,有很多资源都涉及到这一点,但似乎没有什么适合我的特定 (https) 用例.

Forgive me if this has been asked before, there are a number of resources that touch on this, but nothing seems to fit for my specific (https) use-case.

我正在尝试将 https://www.example.com 重定向到 https://example.com.同样,这应该适用于 http://www.example.comhttps://example.com.

I'm trying to redirect https://www.example.com to https://example.com. Likewise, this should work for http://www.example.com to https://example.com.

我已经使用 s3 存储桶的来源设置了 Cloudfront 分配,将 http 重定向到 https,添加了 cname example.com 并添加了我的域证书(适用于 www 子域以及裸域).

I have set up a cloudfront distribution with the origin of an s3 bucket, redirect http to https, added the cname example.com and added my domain certificate (which works for the www subdomain as well as the naked domain).

我还设置了一个单独的发行版,为 www.example.com 设置了 cname,添加了证书并将源设置为单独的 s3 存储桶,该存储桶在(静态网站托管)中将所有请求重定向到 https://example.com.

I have also set up a separate distribution, with a cname for www.example.com, added the certificate and set the origin to a separate s3 bucket that in (static website hosting) redirects all requests to https://example.com.

http://example.com 重定向到 https://example.com,但是 http(s)://www.example.com 到 https://example.com 没有.

Redirection works as expected for http://example.com to https://example.com, however http(s)://www.example.com to https://example.com does not.

在 53 号路由中,我的根域别名为第一个 cloudfront 分布,而 www 别名为第二个.

In route 53 I have the root domain aliased to the first cloudfront distribution and www aliased to the second.

推荐答案

感谢这个答案,我找到了解决方案:Amazon S3 重定向和 Cloudfront

I found the solution thanks to this answer: Amazon S3 Redirect and Cloudfront

简而言之:

如果源只是存储桶 ID,则 Cloudfront 不遵守 S3 中设置的重定向规则.相反,我必须将来源设置为提供的 s3 静态网站主机名.

Cloudfront does not respect the redirection rules setup in S3 if the origin is just the bucket ID. Instead I had to set the origin to the provided s3 static website host name.

这篇关于Cloudfront 使用 ssl 将 www 重定向到裸域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆