Rails,Heroku和Subdomains。我的特殊情况是否可行?

时间:2023-01-12 18:14:46

Here is my scenario:

这是我的情景:

I have an application that will have to support multiple clients. Each client will be given a subdomain for there service. We will also have a brochure website that doesn't have the application, its just a website about the product and how potential clients can setup an account with us.

我有一个必须支持多个客户端的应用程序。每个客户端都将获得一个服务的子域。我们还将有一个没有该应用程序的手册网站,它只是一个关于该产品的网站以及潜在客户如何与我们建立帐户。

Given:

鉴于:

www.mycoolsite.com would point to a brochure app on Heroku. client1.mycoolsite.com, client2.mycoolsite.com and client3.mycoolsite.com would all point to the same SaaS application that could tell the difference between each request and I should be able to handle so they only see their date (i.e. setting a global client_id or something like that)

www.mycoolsite.com将指向Heroku上的宣传册应用程序。 client1.mycoolsite.com,client2.mycoolsite.com和client3.mycoolsite.com都会指向同一个SaaS应用程序,它可以告诉我们每个请求之间的区别,我应该能够处理,所以他们只看到他们的日期(即设置一个全局client_id或类似的东西)

How do I go about doing this? I haven't done a lot with DNS so I'm pretty clueless about where to start with this.

我该怎么做呢?我没有用DNS做过很多,所以我对从哪里开始这个很无能为力。

Thanks.

谢谢。

4 个解决方案

#1


16  

No sweat. We do that now, at Heroku. We happen to use Godaddy for the domain registrar, but any DNS control panel will let you do the same thing.

没有汗水。我们现在在Heroku这样做。我们碰巧将Godaddy用于域名注册商,但任何DNS控制面板都会让您做同样的事情。

The other explanations I read here are a little general, here are the specifics...

我在这里读到的其他解释有点笼统,以下是具体内容......

The explanation at heroku is very good, at : http://docs.heroku.com/custom-domains (there's even a very good screencast shows step by step)

heroku的解释非常好,请访问:http://docs.heroku.com/custom-domains(甚至还有一个非常好的截屏视频一步一步显示)

the key thing is if your ROOT domain (mycoolsite.com) is at Heroku you want to create THREE "A" records, because they do some fault-tolerant crossover magic. So you'd have an A record for

关键是如果你的ROOT域(mycoolsite.com)在Heroku你想创建三个“A”记录,因为它们做了一些容错的交叉魔法。所以你有一个A记录

75.101.163.44
75.101.145.87
174.129.212.2

Now for each subdomain you create a C record

现在为每个子域创建一个C记录

www  -> proxy.heroku.com
client1 -> proxy.heroku.com
client2 -> proxy.heroku.com
client3 -> proxy.heroku.com

NOW on the HEROKu side, you have two apps right? The 'brochure app' and the saas app.

现在在HEROKu方面,你有两个应用程序吗? “宣传册应用程序”和saas应用程序。

Login, and for each app go to Resources -> Addon -> Get More Addons ->Custom Domains (free)

登录,并为每个应用程序转到资源 - >插件 - >获取更多插件 - >自定义域(免费)

for the brochure app, add ONE domain: www.mycoolsite.com

对于宣传册应用程序,添加一个域名:www.mycoolsite.com

for the saas app, add each of the clients, eg:

对于saas应用程序,添加每个客户端,例如:

client1.mycoolsite.com 
client2.mycoolsite.com 
client3.mycoolsite.com

That's it. works like a champ. Have fun.

而已。像冠军一样工作。玩的开心。

#2


2  

What you're trying to do is very feasible, and quite easy to do.

你要做的是非常可行,而且很容易做到。

You're going to need a combination of A and CNAME records. Simply put, A records map host names to IP addresses, and CNAME records act as aliases for A records.

您将需要A和CNAME记录的组合。简单地说,A记录将主机名映射到IP地址,CNAME记录充当A记录的别名。

Let's assume that your SaaS app is hosted at 10.0.0.1 and your Heroku app is at 192.168.0.1, and that you want www.mycoolsite.com and mycoolsite.com to point at the same IP.

假设您的SaaS应用程序托管在10.0.0.1,而您的Heroku应用程序在192.168.0.1,并且您希望www.mycoolsite.com和mycoolsite.com指向相同的IP。

(Note: I've never hosted anything at Heroku, so configuring DNS that may be slightly different)

(注意:我从未在Heroku上托管任何内容,因此配置的DNS可能略有不同)

First thing you'll need is an A record for the domain itself. (I've used BIND Zone File Syntax here - hopefully your DNS provider has a much simpler administration system.)

您需要的第一件事是域名本身的A记录。 (我在这里使用了BIND区域文件语法 - 希望您的DNS提供商有一个更简单的管理系统。)

mycoolsite.com.      A      192.168.0.1    ; heroku
www                  CNAME  mycoolsite.com ; also heroku

These two records tell us that mycoolsite.com should point at Heroku's IP address, and that www.mycoolsite.com is an alternate name for mycoolsite.com, which will also resolve to Heroku's IP address.

这两条记录告诉我们mycoolsite.com应该指向Heroku的IP地址,而www.mycoolsite.com是mycoolsite.com的替代名称,它也将解析为Heroku的IP地址。

Now, let's set up the DNS for your SaaS site. You could set up an A record for each sub-domain, but if you move servers, you'll have a lot of IP addresses to update. The simplest option is to configure one A record, then point your app's sub-domains at it:

现在,让我们为您的SaaS站点设置DNS。您可以为每个子域设置A记录,但如果您移动服务器,则需要更新许多IP地址。最简单的选择是配置一条A记录,然后将应用程序的子域指向它:

sassapp              A      10.0.0.1        ; saas app server canonical name
client1              CNAME  sassapp         ; alias
client2              CNAME  sassapp         ; alias
client3              CNAME  sassapp         ; alias

You can then add as many CNAMEs as you need.

然后,您可以根据需要添加任意数量的CNAME。

#3


1  

I don't see this being an issue. Rails has had support for subdomains like that in the past with help from gems like subdomain_fu. In Rails 3, subdomain support is actually built in and covered by Ryan Bates http://railscasts.com/episodes/221-subdomains-in-rails-3. Take a look at that screencast for a good direction of where to start. I believe you'll need the custom domains add-on for Heroku http://docs.heroku.com/custom-domains.

我不认为这是一个问题。在像subdomain_fu这样的宝石的帮助下,Rails过去曾经支持像过去这样的子域。在Rails 3中,子域支持实际上由Ryan Bates构建并覆盖http://railscasts.com/episodes/221-subdomains-in-rails-3。看看那个截屏视频,了解从哪里开始。我相信你需要Heroku http://docs.heroku.com/custom-domains的自定义域加载项。

#4


0  

This won't be a problem. For DNS set up an A record for mycoolsite.com pointing to the server where you want your application. Set up an A record for www.mycoolsite.com that is configured for heroku. Now you will also want to redirect traffic that comes in on mycoolsite.com without www and redirect to www.mycoolsite.com, this will keep your top-level domain serving up your brochure app. Once requests are getting to your application you can follow the tutorial that raidfive linked to that will help you through handling subdomains inside of your application.

这不会是个问题。对于DNS,为mycoolsite.com设置A记录,指向您想要应用程序的服务器。设置为heroku配置的www.mycoolsite.com的A记录。现在,您还需要重定向mycoolsite.com上没有www的流量并重定向到www.mycoolsite.com,这将保持您的*域名为您的宣传册应用程序提供服务。一旦请求到达您的应用程序,您可以按照raidfive链接到的教程来帮助您处理应用程序内的子域。

#1


16  

No sweat. We do that now, at Heroku. We happen to use Godaddy for the domain registrar, but any DNS control panel will let you do the same thing.

没有汗水。我们现在在Heroku这样做。我们碰巧将Godaddy用于域名注册商,但任何DNS控制面板都会让您做同样的事情。

The other explanations I read here are a little general, here are the specifics...

我在这里读到的其他解释有点笼统,以下是具体内容......

The explanation at heroku is very good, at : http://docs.heroku.com/custom-domains (there's even a very good screencast shows step by step)

heroku的解释非常好,请访问:http://docs.heroku.com/custom-domains(甚至还有一个非常好的截屏视频一步一步显示)

the key thing is if your ROOT domain (mycoolsite.com) is at Heroku you want to create THREE "A" records, because they do some fault-tolerant crossover magic. So you'd have an A record for

关键是如果你的ROOT域(mycoolsite.com)在Heroku你想创建三个“A”记录,因为它们做了一些容错的交叉魔法。所以你有一个A记录

75.101.163.44
75.101.145.87
174.129.212.2

Now for each subdomain you create a C record

现在为每个子域创建一个C记录

www  -> proxy.heroku.com
client1 -> proxy.heroku.com
client2 -> proxy.heroku.com
client3 -> proxy.heroku.com

NOW on the HEROKu side, you have two apps right? The 'brochure app' and the saas app.

现在在HEROKu方面,你有两个应用程序吗? “宣传册应用程序”和saas应用程序。

Login, and for each app go to Resources -> Addon -> Get More Addons ->Custom Domains (free)

登录,并为每个应用程序转到资源 - >插件 - >获取更多插件 - >自定义域(免费)

for the brochure app, add ONE domain: www.mycoolsite.com

对于宣传册应用程序,添加一个域名:www.mycoolsite.com

for the saas app, add each of the clients, eg:

对于saas应用程序,添加每个客户端,例如:

client1.mycoolsite.com 
client2.mycoolsite.com 
client3.mycoolsite.com

That's it. works like a champ. Have fun.

而已。像冠军一样工作。玩的开心。

#2


2  

What you're trying to do is very feasible, and quite easy to do.

你要做的是非常可行,而且很容易做到。

You're going to need a combination of A and CNAME records. Simply put, A records map host names to IP addresses, and CNAME records act as aliases for A records.

您将需要A和CNAME记录的组合。简单地说,A记录将主机名映射到IP地址,CNAME记录充当A记录的别名。

Let's assume that your SaaS app is hosted at 10.0.0.1 and your Heroku app is at 192.168.0.1, and that you want www.mycoolsite.com and mycoolsite.com to point at the same IP.

假设您的SaaS应用程序托管在10.0.0.1,而您的Heroku应用程序在192.168.0.1,并且您希望www.mycoolsite.com和mycoolsite.com指向相同的IP。

(Note: I've never hosted anything at Heroku, so configuring DNS that may be slightly different)

(注意:我从未在Heroku上托管任何内容,因此配置的DNS可能略有不同)

First thing you'll need is an A record for the domain itself. (I've used BIND Zone File Syntax here - hopefully your DNS provider has a much simpler administration system.)

您需要的第一件事是域名本身的A记录。 (我在这里使用了BIND区域文件语法 - 希望您的DNS提供商有一个更简单的管理系统。)

mycoolsite.com.      A      192.168.0.1    ; heroku
www                  CNAME  mycoolsite.com ; also heroku

These two records tell us that mycoolsite.com should point at Heroku's IP address, and that www.mycoolsite.com is an alternate name for mycoolsite.com, which will also resolve to Heroku's IP address.

这两条记录告诉我们mycoolsite.com应该指向Heroku的IP地址,而www.mycoolsite.com是mycoolsite.com的替代名称,它也将解析为Heroku的IP地址。

Now, let's set up the DNS for your SaaS site. You could set up an A record for each sub-domain, but if you move servers, you'll have a lot of IP addresses to update. The simplest option is to configure one A record, then point your app's sub-domains at it:

现在,让我们为您的SaaS站点设置DNS。您可以为每个子域设置A记录,但如果您移动服务器,则需要更新许多IP地址。最简单的选择是配置一条A记录,然后将应用程序的子域指向它:

sassapp              A      10.0.0.1        ; saas app server canonical name
client1              CNAME  sassapp         ; alias
client2              CNAME  sassapp         ; alias
client3              CNAME  sassapp         ; alias

You can then add as many CNAMEs as you need.

然后,您可以根据需要添加任意数量的CNAME。

#3


1  

I don't see this being an issue. Rails has had support for subdomains like that in the past with help from gems like subdomain_fu. In Rails 3, subdomain support is actually built in and covered by Ryan Bates http://railscasts.com/episodes/221-subdomains-in-rails-3. Take a look at that screencast for a good direction of where to start. I believe you'll need the custom domains add-on for Heroku http://docs.heroku.com/custom-domains.

我不认为这是一个问题。在像subdomain_fu这样的宝石的帮助下,Rails过去曾经支持像过去这样的子域。在Rails 3中,子域支持实际上由Ryan Bates构建并覆盖http://railscasts.com/episodes/221-subdomains-in-rails-3。看看那个截屏视频,了解从哪里开始。我相信你需要Heroku http://docs.heroku.com/custom-domains的自定义域加载项。

#4


0  

This won't be a problem. For DNS set up an A record for mycoolsite.com pointing to the server where you want your application. Set up an A record for www.mycoolsite.com that is configured for heroku. Now you will also want to redirect traffic that comes in on mycoolsite.com without www and redirect to www.mycoolsite.com, this will keep your top-level domain serving up your brochure app. Once requests are getting to your application you can follow the tutorial that raidfive linked to that will help you through handling subdomains inside of your application.

这不会是个问题。对于DNS,为mycoolsite.com设置A记录,指向您想要应用程序的服务器。设置为heroku配置的www.mycoolsite.com的A记录。现在,您还需要重定向mycoolsite.com上没有www的流量并重定向到www.mycoolsite.com,这将保持您的*域名为您的宣传册应用程序提供服务。一旦请求到达您的应用程序,您可以按照raidfive链接到的教程来帮助您处理应用程序内的子域。