Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何允许客户子域站点使用自己的域_Ruby On Rails_Dns_Subdomain - Fatal编程技术网

Ruby on rails 如何允许客户子域站点使用自己的域

Ruby on rails 如何允许客户子域站点使用自己的域,ruby-on-rails,dns,subdomain,Ruby On Rails,Dns,Subdomain,我有一个rails应用程序,客户可以在其中注册并获得自定义子域站点/url,如下所示: before_filter :load_customer_from_host def load_customer_from_host # Strip "www." from host name to search only by domain. hostname = request.host.sub(/^www\./, '') @customer = Customer.find_by_host

我有一个rails应用程序,客户可以在其中注册并获得自定义子域站点/url,如下所示:

before_filter :load_customer_from_host

def load_customer_from_host
  # Strip "www." from host name to search only by domain.
  hostname = request.host.sub(/^www\./, '')

  @customer = Customer.find_by_host!(hostname)
rescue ActiveRecord::RecordNotFound
  render(:partial => 'customer_not_found', :layout => 'application', :status => :not_found)
end
  • customer1.myapp.com
  • customer2.myapp.com
  • customer3.myapp.com
我需要采取哪些步骤来允许客户使用自己注册的域名,以便他们的域名指向我的应用程序

因此,在上面的示例中,如果“customer1”拥有“customer1.com”-我如何设置我的应用程序,以便将对“customer1.com”的任何请求发送到“customer1.myapp.com”?另外,我的客户需要做什么


谢谢。

您的客户需要为他们的域设置DNS,以将其或其一部分指向您的地址。这可能很难协调,尤其是当您托管服务的服务器的地址可能会不时更改时。将客户的子域路由到您的子域要容易得多

您还需要一个将客户的域映射到客户帐户的查找表。这通常表示为以下内容:

before_filter :load_customer_from_host

def load_customer_from_host
  # Strip "www." from host name to search only by domain.
  hostname = request.host.sub(/^www\./, '')

  @customer = Customer.find_by_host!(hostname)
rescue ActiveRecord::RecordNotFound
  render(:partial => 'customer_not_found', :layout => 'application', :status => :not_found)
end
这假定您有一个客户模型,其中的“主机”字段设置为“customer1.myapp.com”或“customer1.com”,只要与主机字段匹配即可

设置应用程序时,需要有一个虚拟主机配置,以响应所有任意域名。如果它是唯一托管的站点,这很容易做到,因为这是默认行为。如果您在共享主机上执行此操作,则可能需要为每个客户域专门配置一个别名,这可能会造成麻烦