如何在heroku应用程序中指向一个域 [英] How to point a domain at a heroku application

查看:93
本文介绍了如何在heroku应用程序中指向一个域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我已经在我的VPS上完成了这项工作,但我从来没有为heroku应用程序做过这件事,现在我必须为一家相当大的公司做这件事,所以我真的想要一个简单的关于如何这样做。



我已阅读这些说明,我对它们究竟意味着什么仍然有点不清楚。再次,如果我有更多时间,我会购买一些垃圾域并自己测试,但我没有时间在我身边,需要第一时间做对!



幸运的是,此时不需要SSL。



以下是我可以收集的内容,我需要做的是将url 指向www.foobaryfoobs .com 在我的应用程序中,运行在 warm-chamber-1882.herokuapp.com 。请改正我:




<1>我添加 www.foobaryfoobs.com 到包含应用程序的本地存储库。



我假设我通过导航到本地机器上的存储库并运行:

  $ heroku域名:添加www.foobaryfoobs.com 




  • 这是如何工作的?它是否需要将某些配置文件更新到需要添加到存储库的位置,然后推送到heroku?


  • 是否有任何警告或最佳实践?我应该添加哪些其他域名? heroku域名:加* .foobaryfoobs.com ,例如?


  • Heroku建议我们使用上述通配符域在这里。为什么?


    $ hr
    $ b

    2)登录创建<$的注册器c $ c> www.foobaryfoobs.com 并导航至其控制面板。



    3)将域的CNAME记录更新为 warm-chamber-1882.herokuapp.com




    • 我是大部分完成了?现在我只是等待吗?

    • 该域名附有数十封电子邮件。只要我不碰MX记录,我应该没事? 什么是根域?为什么要添加它?


    • 为什么要关注这个问题:



    • 一些DNS主机提供了一种使用自定义记录类型在
      区域顶点获得类似CNAME功能的方法。


      blockquote>




      4)更新域的FORWARD / URL记录,使 foobaryfoobs.com 指向 www.foobaryfoobs.com




      • 对于一个nooby,请解释为什么这是必要的。






      3结论性问题:



      1)这是应该如何设置的:



      应用程序:

        warm-chamber-1882.herokuapp.com 



      <应该有以下配置(保存在一些奇怪的配置文件中,我不介意更多地了解它):

       域名:
      www.foobaryfoobs.com
      * .foobaryfoobs.com

      域:

        www.foobaryfoobs.com 

      应该有以下记录:

        CNAME:warm-chamber-1882.herokuapp。 com 
      URL / FORWARD:foobaryfoobs.com目标:www​​.foobaryfoobs.com
      MX:*只要我不碰它们,电子邮件仍然可以使用*



      确保您的DNS合作非常重要nfiguration与您添加到Heroku中的
      自定义域名一致。特别是,如果您已将
      配置为* .example.com的DNS以指向
      example.herokuapp.com,请确保您还运行heroku域名:add
      * .example.com 。否则,恶意的人可能会将baddomain.example.com添加到他们的Heroku应用程序,并接收您的应用程序的预计
      的流量。


      3)我应该如何调整具有SSL后端部分的网站的步骤? > A。


      $ heroku域名:添加www.foobaryfoobs.com

      这个怎么用?它是否需要将某些配置文件更新到我需要添加到存储库的位置,然后推送到heroku?





      1. 我不知道它在内部是如何工作的,但这个命令相当于在apache配置文件中添加 ServerName ,没有这个请求时<$ c $因为 dns 但它会被转发到heroku,但是heroku无法确定你的应用程序。你会看到下面的图像。



        这就是为什么他们需要你的域名,以便他们知道哪些应用属于哪个域名。他们也需要它来实现域优先目的。只要您允许用户访问Heroku子域,即 warm-chamber-1882.herokuapp.com ,代码中不需要进行任何更改。如果您不想让用户访问heroku子域名,您必须传递 301 http状态,以便将其重定向到您的实际域名,即 www.foobaryfoobs.com 。为此,您已将这添加到您的应用程序控制器中

          before_action:forward_to_domain_if_heroku_subdomain 

        private

        def forward_to_domain_if_heroku_subdomain
        if request.host =='warm-chamber-1882.herokuapp.com'
        redirect_tohttp://www.foobaryfoobs.com,状态:301
        结束
        结束





      这里有任何警告或最佳做法吗?我应该添加哪些其他域名? heroku域名:添加* .foobaryfoobs.com,例如?





      1. 如果您只想要使用 www.foobaryfoobs.com 作为你的域名,这个命令就足够了,即

          heroku域名:添加www.foobaryfoobs.com 


      2. 如果您想分配裸域 foobaryfoobs.com 那么你也必须运行

          heroku域名:添加foobaryfoobs.com 


      3. 如果您的应用程序使用子域名,如子域名。 foob​​aryfoobs.com 那么你也必须运行

          heroku域名:添加foobaryfoobs.com 





      2)登入注册商创建了www.foobaryfoobs.com并导航到其控制面板。

      为了保持价值,您必须使用DNS管理工具。 b
      $ b


      3)将网域的CNAME记录更新为指向warm-chamber-1882.herokuapp.com


      是的。


      我大部分都完成了吗?现在,我只是等待吗?


      是的,但也有其他的事情。


      是否没有与IP相关的内容?



      <是的,没有与IP相关的东西。


      该域名附有数十封电子邮件。只要我不碰MX记录,我应该没问题?


      是的。


      什么是根域?我为什么要添加它?

      如果您想接受来自 warm-chamber-1882.herokuapp.com (不是 www。warm-chamber-1882.herokuapp.com ),那么你必须添加它。


      为什么我应该关心这个问题:
      某些DNS主机提供了一种在区域顶点使用类似CNAME的功能自定义记录类型。





      1. 是的。他们正在谈论 ALIAS ANAME 类型的记录。 (DNSimple提供它)。你必须关心它,因为从那个自定义记录类型很容易添加记录。它们就像预先定义的模板,例如 ALIAS A 记录的模板。




      4)更新域的FORWARD / URL记录,以便foobaryfoobs.com指向www.foobaryfoobs。对于一个nooby,请解释为什么这是必要的。




      这是必要的,因为 www.foobaryfoobs.com foobaryfoobs.com 与<$ c $相同c> images.google.com news.google 不同。 www 没什么特别的,它只是一个子域。如果你不这样做,用户不能从 foobaryfoobs.com 使用你的站点,但可以访问 www.foobaryfoobs.com

      B。




      1)这是应该如何设置的?

      是的,它是正确的。但是如果你想允许 foobaryfoobs.com www.foobaryfoobs.com ,你必须做下面的表格。如果您的应用没有使用除 www 以外的任何子域,则不需要 *。foobaryfoobs.com 记录。添加 *。foobaryfoobs.com

       类型|名称|内容
      ---------------------------------------
      ALIAS | foob​​aryfoobs.com | yoursite.herokuapp.com
      CNAME | www.foobaryfoobs.com | yoursite.herokuapp.com




      务必确保您的DNS配置同意与您添加到Heroku的自定义域名。特别是,如果您已将* .example.com的DNS配置为指向example.herokuapp.com,请确保您还运行heroku域:add * .example.com。否则,恶意的人可能会将baddomain.example.com添加到他们的Heroku应用程序中,并接收适用于您的应用程序的流量。

      是。此外,你不必担心这一点。如果恶意用户可以在你的域名中设置子域名,那么他有能力去做大量的破坏:P。实际上,恶意用户无法访问您的DNS管理工具,因此您很安全。

      While I've done this on my VPS, I've never done this for a heroku application, and now I have to do it for a fairly large company so I really want a simple list of bullet-points in how to do this.

      I've read these instructions, and I'm still a little bit unclear on what exactly they mean. Again, if I had more time I'd buy some rubbishy domain and test it myself, but I don't have time on my side and need to get this right first time!

      Thankfully, no SSL is required at this time.

      Here's what I can gather I need to do to point the url www.foobaryfoobs.com at my application, running at warm-chamber-1882.herokuapp.com. Please correct me:


      1) I add www.foobaryfoobs.com to the local repository containing the application.

      I presume I do this by navigating to the repository on my local machine and running:

      $ heroku domains:add www.foobaryfoobs.com
      

      • How does this work? Does it update some configuration file somewhere that I need to add to the repository and then push up to heroku?

      • Are there any caveats or best practices here? What other domains should I add? heroku domains:add *.foobaryfoobs.com, for example?

      • Heroku advises we use the above wildcard domain here. Why?


      2) Log into the registrar that created www.foobaryfoobs.com and navigate to its control panel.

      3) Update the domain's CNAME record to point at warm-chamber-1882.herokuapp.com

      • Am I done for the most part? Now do I just wait?

      • Is there no IP related stuff?

      • The domain has several dozen emails attached to it. As long as I don't touch the MX record, I should be fine?

      • What's a root domain? Why should I add it?

      • Why should I care that:

      Some DNS hosts provide a way to get CNAME-like functionality at the zone apex using a custom record type.


      4) Update the domain's FORWARD / URL record so that foobaryfoobs.com points to www.foobaryfoobs.com

      • For a nooby, please explain why this is necessary.

      3 Conclusive Questions:

      1) Is this how it should be set up?:

      The app:

      warm-chamber-1882.herokuapp.com
      

      Should have the following configurations (saved in some weird config file that I wouldn't mind knowing more about about):

      domains:
      www.foobaryfoobs.com
      *.foobaryfoobs.com
      

      The domain:

      www.foobaryfoobs.com
      

      Should have the following records:

      CNAME: warm-chamber-1882.herokuapp.com
      URL / FORWARD: foobaryfoobs.com target: www.foobaryfoobs.com
      MX: *as long as I don't touch them the emails will still work*
      

      2) Am I covered against:

      It’s important to make sure your DNS configuration agrees with the custom domains you’ve added to Heroku. In particular, if you have configured your DNS for *.example.com to point to example.herokuapp.com, be sure you also run heroku domains:add *.example.com. Otherwise, a malicious person could add baddomain.example.com to their Heroku app and receive traffic intended for your application.

      3) How should I adjust the steps for a site that has an SSL backend section?

      解决方案

      A.

      $ heroku domains:add www.foobaryfoobs.com

      How does this work? Does it update some configuration file somewhere that I need to add to the repository and then push up to heroku?

      1. I dont know exactly how does it works internally but this command is equivalent of adding ServerName in apache config file, without this when request comes to www.foobaryfoobs.com it will be forwarded to heroku because of dns but heroku fail to determine your app. You will see the below image.

        That's why they need your domain so they know which apps belongs to which domains. They also need it for domain precedence purpose. No changes are required in your code as long as you are okay to allow your user to access Heroku subdomain ie warm-chamber-1882.herokuapp.com. If you dont want user to access heroku subdomain you have to pass 301 http status so it will be redirected to your actual domain i.e www.foobaryfoobs.com . For this you have add this in your application controller

        before_action :forward_to_domain_if_heroku_subdomain
        
        private 
        
        def forward_to_domain_if_heroku_subdomain
          if request.host == 'warm-chamber-1882.herokuapp.com'
            redirect_to "http://www.foobaryfoobs.com" , status: 301
          end
        end
        

      Are there any caveats or best practices here? What other domains should I add? heroku domains:add *.foobaryfoobs.com, for example?

      1. if you ONLY want to use www.foobaryfoobs.com as your domain, this command is suffice ie

        heroku domains:add www.foobaryfoobs.com
        

      2. If you want to assign naked domain foobaryfoobs.com then you ALSO have to run

        heroku domains:add foobaryfoobs.com
        

      3. If you application use subdomains like subdomain.foobaryfoobs.com then you also have to run

        heroku domains:add foobaryfoobs.com
        

      2) Log into the registrar that created www.foobaryfoobs.com and navigate to its control panel.

      To be precious, you have to do DNS management tool.

      3) Update the domain's CNAME record to point at warm-chamber-1882.herokuapp.com

      Yes.

      Am I done for the most part? Now do I just wait?

      Yes, but there are also other things.

      Is there no IP related stuff?

      Yes, there is no ip related stuff.

      The domain has several dozen emails attached to it. As long as I don't touch the MX record, I should be fine?

      Yes.

      What's a root domain? Why should I add it?

      if you want to accept requests from user at warm-chamber-1882.herokuapp.com (not www. warm-chamber-1882.herokuapp.com) then you have to add it.

      Why should I care that: Some DNS hosts provide a way to get CNAME-like functionality at the zone apex using a custom record type.

      1. Yes. They are talking about ALIAS or ANAME type of records. (DNSimple provides it). You have to care it because from that custom-record-type it is easily to add record. They are like pre defined templates eg ALIAS is template of A record.

      4) Update the domain's FORWARD / URL record so that foobaryfoobs.com points to www.foobaryfoobs.com

      For a nooby, please explain why this is necessary.

      It is necessary because www.foobaryfoobs.com and foobaryfoobs.com are different in a same way like images.google.com and news.google differs. www is nothing special it is just a subdomain. If you dont do this, user can't use your site from foobaryfoobs.com but can access www.foobaryfoobs.com.

      B.

      1) Is this how it should be set up?

      Yes, it is correct. But if you want to allow foobaryfoobs.com and www.foobaryfoobs.com, you have to do something like below table. You dont require *.foobaryfoobs.com record if your app doesn't use any subdomain except www. It is bad practice actually to add *.foobaryfoobs.com .

      Type  |     Name             | Content
      ---------------------------------------
      ALIAS | foobaryfoobs.com     | yoursite.herokuapp.com
      CNAME | www.foobaryfoobs.com | yoursite.herokuapp.com
      

      It’s important to make sure your DNS configuration agrees with the custom domains you’ve added to Heroku. In particular, if you have configured your DNS for *.example.com to point to example.herokuapp.com, be sure you also run heroku domains:add *.example.com. Otherwise, a malicious person could add baddomain.example.com to their Heroku app and receive traffic intended for your application.

      Yes. Moreover you dont have to worry about this. If the malicious user can set subdomain at your domain then he capable to do much destruction :P. Actually, malicious user can't access your DNS management tool so you're safe.

      这篇关于如何在heroku应用程序中指向一个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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