Rails, Heroku and Subdomains. Is my special case scenario feasible? Rails, Heroku and Subdomains. Is my special case scenario feasible? ruby-on-rails ruby-on-rails

Rails, Heroku and Subdomains. Is my special case scenario feasible?


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.

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)

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

75.101.163.4475.101.145.87174.129.212.2

Now for each subdomain you create a CNAME record

www  -> proxy.heroku.comclient1 -> proxy.heroku.comclient2 -> proxy.heroku.comclient3 -> proxy.heroku.com

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

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

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

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

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


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.

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.

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

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.)

mycoolsite.com.      A      192.168.0.1    ; herokuwww                  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.

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:

sassapp              A      10.0.0.1        ; saas app server canonical nameclient1              CNAME  sassapp         ; aliasclient2              CNAME  sassapp         ; aliasclient3              CNAME  sassapp         ; alias

You can then add as many CNAMEs as you need.


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.