在 Rails 上具有自定义域的多租户 [英] multi tenant with custom domain on rails

查看:20
本文介绍了在 Rails 上具有自定义域的多租户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个像 shopify 这样的多租户应用程序,想知道如何在指向同一个应用程序实例的服务器上创建自定义域?例如:

I'm creating a multi tenant application like shopify and wanna know how can I create custom domain on server that points to the same application instance? For example:

app1.mysystem.com == www.mystore.com
app2.mystem.com == www.killerstore.com

我需要像 Google Apps 一样在 CNAME 上进行该配置吗?如果是这样,我该怎么做?有没有一些好的论文展示这是如何工作的?

I need to do that config on CNAME like Google Apps? If so, how can I do that? Is there some good paper showing how this works ?

PS:app1 和 app2 指向同一个应用程序!谢谢

PS: app1 AND app2 points to the same application! Thanks

推荐答案

我有类似的设置并且正在使用 nginX.我为便于维护所做的工作是接受来自 nginx 的所有连接,并在我的应用程序中进行过滤.

I have a similar setup and am using nginX. What I did for ease of maintenance was accepted all the connections from nginx and did the filtering in my app.

# application_controller.rb
before_filter :current_client

private
def current_client
  # I am using MongoDB with Mongoid, so change the syntax of query accordingly
  @current_client ||= Client.where(:host => request.host).first
  render('/public/404.html', :status => :not_found, :layout => false) unless @current_client
end

您可以让您的客户拥有一个域记录,其中的域/子域指向 you_ipyour_domain_pointing_to_your_ip.com,并在表单中捕获并保存在数据库中.然后更改 current_client 中的查询,如:

You can have your clients have a domain record with there domain/subdomain pointing to you_ip or your_domain_pointing_to_your_ip.com and capture that in a form and save in database. Then alter the query in current_client like:

@current_client ||= Client.or(:host => request.host).or(:alias => request.host).first

这篇关于在 Rails 上具有自定义域的多租户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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