Heroku使用AWS从example.com重定向到www.example.com并保留HTTPS

编程入门 行业动态 更新时间:2024-10-23 10:33:29
本文介绍了Heroku使用AWS从example重定向到www.example并保留HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个使用SSL证书设置的Heroku应用,并且我的DNS不允许Apex级别的CNAME记录.意思是,我不能将A记录指向我的Heroku应用URL(A级记录只能是IP地址,而Heroku无法提供静态IP).

I have a Heroku app set up with SSL certificates, and my DNS does not allow CNAME records at the Apex level. Meaning, I cannot point my A Record at my Heroku app URL (A level records can only be IP addresses and Heroku cannot provide a static IP).

还有其他建议使用其他DNS提供程序的方法(包括在堆栈上和heroku的指南中),但是我想尝试通过AWS(特别是Route53)解决此问题,同时还将我们的保留在域中用于SSL.

There other methods (both here on stack and on heroku's guides) that recommend using other DNS providers, but I would like to try and solve this with AWS (Specifically Route53), while also retaining our in the domain for SSL.

我找到了一些有关如何执行此操作的指南,但似乎有些复杂(标头混乱,无法保留https等).我将在下面提供概述我如何实现这一目标的答案,但鼓励讨论我的解决方案可能会产生什么影响.

I found some guides on how to do this, but there seemed to be complications (headers messed up, cannot retain https etc). I will provide an answer below outlining how I achieved this, but encourage discussion on what repercussions my solution may incur.

推荐答案

我在Heroku网站上发现了该指南: 为您的Heroku应用配置Amazon Route 53 DNS

I discovered this guide on the Heroku website: Configuring Amazon Route 53 DNS for Your Heroku App

解决方案的概述是创建一个S3存储桶作为静态网站主机,该主机仅重定向到您的Route53托管区域.这是基本步骤:

The outline of the solution is to create an S3 bucket as a static website host that simply redirects to your Route53 hosted zone. Here are the basic steps:

  • 使用域(example)在Route 53管理控制台上创建一个新的托管区域
  • 为www.example创建一个CNAME条目,并将其值设置为您的heroku自定义域(www.example.herokudns)
  • 创建一个与您的域(example)同名的S3存储桶,并将其设置为静态网站托管服务器
  • 在静态网站托管的设置中,将此设置为重定向请求",并将目标设置为www.example,将协议设置为https
  • 返回Route 53,并添加一个目标为您新创建的存储桶的A Level别名
  • 最后将您的DN Providers名称服务器指向新的Route 53托管区域(您可以从管理控制台的侧面板中获取名称服务器列表)
  • Create a new hosted zone on your Route 53 Management Console with your domain (example)
  • Create a CNAME entry for www.example with the value set as your heroku custom domain (www.example.herokudns)
  • Create an S3 Bucket with the same name as your domain (example), and set it as a static website host
  • In the settings for static website hosting set this to "Redirect Requests" and set the target as www.example and the protocol to https
  • Return to Route 53 and add an A Level Alias with the target as your newly created bucket
  • Finally point your DN Providers Name servers at your new Route 53 hosted zone (you can get the list of name servers from the sidepanel in your management console)
  • 就是这样!在您的名称服务器上的TTL过期后,您的网站应该已启动并正在运行,并且example和www.example

    And that's it! After the TTL expires on your Name Servers your site should be up and running and both example and www.example

    更多推荐

    Heroku使用AWS从example.com重定向到www.example.com并保留HTTPS

    本文发布于:2023-11-01 11:41:44,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1549248.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:重定向   AWS   Heroku   www   HTTPS

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!