我正在尝试为我的 heroku 应用程序设置 SSL。我正在使用基于主机名的 SSL 插件。赫罗库文档 http://devcenter.heroku.com/articles/ssl#customdomain_ssl_wwwyourdomaincom陈述如下:
Hostname based SSL will not work with root domains as it relies on CNAME
aliasing of your custom domain names. CNAME aliasing of root domains is
an RFC violation.
正如预期的那样,当我使用以下命令访问该网站时,一切正常www子域,即https://www.foo.com https://www.foo.com。当我访问时浏览器抱怨https://foo.com https://foo.com因为所提供的证书是针对 heroku.com 的。
我的结论是我必须重定向流量foo.com to www.foo.com来解决这个问题。我正在考虑以下方法:
1)基于DNS的重定向
DNS 提供商 Zerigosupports https://www.zerigo.com/blog/2009/07/dns_updates_url_redirection_and_example_code_for_the_api the redirect记录。我遇到了一个question https://stackoverflow.com/questions/5116052/how-could-i-redirect-a-root-level-domain-to-www-subdomain-with-zerigo-dns-on-hero关于SO上的类似主题。我尝试了该解决方案,它仅适用于 HTTP 重定向(Zerigo 文档证实了这一点)。
我的 Zerigo 配置:
foo.com A x.x.x.x
foo.com redirect http://www.foo.com
www.foo.com CNAME zzz.amazonaws.com
2) 基于机架的重定向
添加基于机架的中间件来执行重定向。这规范主机 https://github.com/tylerhunt/rack-canonical-hostgem 提供了这样的支持。
use CanonicalHost do
case Rails.env.to_sym
when :staging then 'staging.foo.com'
when :production then 'www.foo.com'
end
end
我想知道是否有更好的解决方案(除非切换到每月 100 美元的基于 IP 的 SSL)