Heroku redirect from example.com to www.example.com retaining HTTPS using AWS

天大地大妈咪最大 提交于 2019-12-14 03:55:55

问题


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).

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 https:// in the domain for SSL.

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.


回答1:


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

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:

  1. Create a new hosted zone on your Route 53 Management Console with your domain (example.com)
  2. Create a CNAME entry for www.example.com with the value set as your heroku custom domain (www.example.com.herokudns.com)
  3. Create an S3 Bucket with the same name as your domain (example.com), and set it as a static website host
  4. In the settings for static website hosting set this to "Redirect Requests" and set the target as www.example.com and the protocol to https
  5. Return to Route 53 and add an A Level Alias with the target as your newly created bucket
  6. 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)

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



来源:https://stackoverflow.com/questions/53423092/heroku-redirect-from-example-com-to-www-example-com-retaining-https-using-aws

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