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

问题描述

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



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



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



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




我添加 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记录,我应该没事? 什么是根域?为什么要添加它?


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


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




      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
        结束
        结束







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

          heroku域名:添加www.foobaryfoobs.com 


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

          heroku域名:添加foobaryfoobs.com 


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

          heroku域名:添加foobaryfoobs.com 




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

      是的。

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



      是的。

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




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





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

      B。



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

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



      是。此外,你不必担心这一点。如果恶意用户可以在你的域名中设置子域名,那么他有能力去做大量的破坏: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:


      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:

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

      解决方案

      A.

      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
        

      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
        

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

      Yes.

      Yes, but there are also other things.

      Yes, there is no ip related stuff.

      Yes.

      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.

      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.

      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.

      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
      

      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应用程序中指向一个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 00:12