多租户与在轨道上的自定义域 [英] multi tenant with custom domain on rails

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

问题描述

我创建多租户应用程序一样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

我需要做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_ip your_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

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

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