简体   繁体   English

多个域通过显示不同内容的名称服务器指向单个Heroku Rails应用程序?

[英]Multiple domains pointing to single Heroku Rails app via nameservers displaying different content?

We have a Rails 3 app which allows users to create a profile and access it with a subdomain. 我们有一个Rails 3应用程序,允许用户创建一个配置文件并使用子域访问它。 So for example: 例如:

  • user1.app.com user1.app.com
  • user2.app.com user2.app.com
  • user3.app.com user3.app.com

Now, suppose they wanted to point their own domain name to their profile, so www.user1.com shows user1.app.com , and www.user1.com/my-content/ shows user1.app.com/my-content/ . 现在,假设他们想将自己的域名指向他们的个人资料,因此www.user1.com显示user1.app.comwww.user1.com / my-content /显示user1.app.com/my-content/ Is it possible for them to simply change their nameservers to point to us, and we handle the routing? 他们是否可以简单地更改他们的名称服务器以指向我们,我们处理路由? I'm afraid it would be a deal breaker if the user had to do any DNS configuration beyond just changing their nameservers. 如果用户除了更改名称服务器之外不得不进行任何DNS配置,我担心这将是一个交易破坏者。

Thanks! 谢谢!

This is really two questions. 这真的是两个问题。 So I guess I'll answer it like that. 所以我想我会这样回答。

How can I allow customers to add a custom domain to my heroku-based app? 如何允许客户将自定义域添加到基于heroku的应用程序?

So, in your example, their domain name is www.user1.com 因此,在您的示例中,他们的域名是www.user1.com

Two things need to happen 有两件事需要发生

  1. www.user1.com needs to be added to your heroku domains for the app 需要将www.user1.com添加到应用程序的heroku域中
  2. the dns for www.user1.com needs to be set to the heroku servers 需要将www.user1.com的dns设置为heroku服务器

In order to add this new domain, I guess you need to store the custom domain in the app, and when it is changed, or created, ensure a queued task is setup to push this config change to heroku. 为了添加这个新域,我猜你需要在应用程序中存储自定义域,当它被更改或创建时,确保设置排队任务以将此配置更改推送到heroku。

In order to do the dns correctly, I hope it is enough that they add a CNAME for user1.app.com . 为了正确地执行dns,我希望他们为user1.app.com添加CNAMEuser1.app.com Therefore, if you have a wildcard CNAME linking to heroku's dns, you can avoid the type of downtime that can occur if Heroku gets DOS-ed again. 因此,如果您有一个链接到heroku的dns的通配符CNAME,则可以避免在Heroku再次进行DOS操作时可能发生的停机类型。

How can I show content based on domain, rather than just subdomain? 如何基于域显示内容,而不仅仅是子域?

Well, somehow you already differentiate user1.app.com from user2.app.com 好吧,不知怎的,你已经将user1.app.comuser2.app.com

Maybe you just sniffed request.host . 也许你只是嗅到了request.host Now you just have to try the custom domain first. 现在,您只需先尝试自定义域。

Maybe this'll work. 也许这会奏效。

before_filter :set_client

def set_client
  @client = Client.find_by_custom_domain(request.host) || Client.find_by_subdomain(request.host.split(".").first)
  unless @client
    raise "unrecognised domain #{request.host}"
  end
end

You need to get them first of all have them set www.user1.com to point to proxy.heroku.com (or setup your own cname entry to proxy.heroku.com and get them to cname their domains to that) and then you need to register their custom domain with your heroku app so the correct application responds at Heroku stored against their account?? 首先你需要让他们设置www.user1.com指向proxy.heroku.com(或者设置你自己的cname条目到proxy.heroku.com并让他们将域名命名为)然后你需要使用您的heroku应用程序注册他们的自定义域名,以便正确的应用程序响应他们的帐户存储的Heroku? in your application so it can be matched on incoming requests. 在您的应用程序中,以便它可以匹配传入的请求。

This technique is employed in the Locomotive Rails CMS so I'd suggest looking at that - it uses the Heroku gem INSIDE the application so custom domains can be added via the site administrator which in turn talks to the Heroku API to add the custom domain to the application. 这种技术在Locomotive Rails CMS中使用,所以我建议看一下 - 它使用Heroku gem INSIDE应用程序,因此可以通过站点管理员添加自定义域,后者又与Heroku API对话以添加自定义域应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM