简体   繁体   English

如何允许客户子域网站使用自己的域

[英]How to allow customer subdomain sites to use their own domain

I have a rails app where customers sign up and get a custom subdomain site/url like this: 我有一个rails应用程序,客户注册并获得这样的自定义子域网站/网址:

  • customer1.myapp.com customer1.myapp.com
  • customer2.myapp.com customer2.myapp.com
  • customer3.myapp.com customer3.myapp.com

What are the steps I need to take to allow a customer to use their own registered domain name such that their domain points to my app? 允许客户使用自己的注册域名以使其域名指向我的应用程序需要采取哪些步骤?

So, in the example above, if "customer1" owns "customer1.com" - how can I setup my app so that any requests to "customer1.com" are sent to "customer1.myapp.com"? 因此,在上面的示例中,如果“customer1”拥有“customer1.com” - 如何设置我的应用程序以便将对“customer1.com”的任何请求发送到“customer1.myapp.com”? Also, what would my customer need to do on his end? 另外,我的客户需要做什么呢?

Thanks. 谢谢。

Your customer is going to need to set up DNS For their domain to point it, or part of it, to your address. 您的客户需要为其域名设置DNS,以便将其指向您的地址或将其中的一部分指向您的地址。 This can be tricky to coordinate, especially if the address of the server you're hosting the service on can change from time to time. 这可能很难协调,特别是如果您托管服务的服务器的地址可能会不时更改。 It's a lot easier to route a customer's subdomain to your subdomain. 将客户的子域路由到子域更容易。

You'll also need a lookup table that maps a customer's domain to a customer's account. 您还需要一个查找表,将客户的域映射到客户的帐户。 That's typically expressed as something like this: 这通常表示为:

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

That presumes you have a Customer model with a 'host' field set with something like 'customer1.myapp.com' or 'customer1.com', whatever matches the host field. 这假设您的客户模型的“主机”字段设置为“customer1.myapp.com”或“customer1.com”,与主机字段匹配。

When you set up your app, you will need to have a virtual host configuration that responds to all arbitrary domain names. 设置应用程序时,您需要具有响应所有任意域名的虚拟主机配置。 This is easy to do if it is the only site hosted, since that is the default behaviour. 如果它是唯一托管的站点,这很容易做到,因为这是默认行为。 If you're doing this on shared hosting you may have to configure an alias for each customer domain specifically, which can be a nuisance. 如果您在共享主机上执行此操作,则可能必须专门为每个客户域配置别名,这可能会造成麻烦。

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

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