20

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)

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.

Thanks.

aarona
  • 35,986
  • 41
  • 138
  • 186
  • 1
    I am also having this problem and have not found a solution (even with contacting heroku support). The closest I have found is the same as jpwynns answer, however if you are letting people signup for a subdomain of your SaaS application through a registration page, then that page will also need to be adding the subdomain to your heroku app (you can't use a wildcard as it will clash with your www and Heroku doesn't allow it). This tightly coupled integration between your app and the host may not be desirable. If someone solves this I will be very happy. – Joel Friedlaender Mar 06 '11 at 11:54

4 Answers4

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.

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.44
75.101.145.87
174.129.212.2

Now for each subdomain you create a CNAME record

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.

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.

jpw
  • 18,697
  • 25
  • 111
  • 187
  • Wow, thanks for the very details answer, +1. I will try this out and most likely accept this answer when I get around to do this today. :) – aarona Feb 02 '11 at 16:54
  • if your site's public address is without the `www`, like `twitter.com` instead of `www.twitter.com`, and you want to also do what you're talking about (2 apps, the 'main' one, and say a staging one), can you have `site.com` and `staging.site.com` like this? – Lance May 20 '11 at 22:46
  • This should really be on the Heroku Dev Center as above, in text, instead of just in video format. – chanderson0 Jul 18 '11 at 04:03
  • 3
    Hello, I found this very helpful, however, my app creates the users subdomain automatically. Therefore as soon as my client registers into my app, I automatically create myclient.myapp.com...Does this mean that i have to manually create a C record for each of my customers? – jalagrange Aug 29 '11 at 21:43
  • 3
    @jalagrange you should be able to use Heroku's wildcard subdomains for that, it costs $5 a month though. – Shane Feb 16 '12 at 03:03
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.

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

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 name
client1              CNAME  sassapp         ; alias
client2              CNAME  sassapp         ; alias
client3              CNAME  sassapp         ; alias

You can then add as many CNAMEs as you need.

dnch
  • 9,565
  • 2
  • 38
  • 41
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.

raidfive
  • 6,603
  • 1
  • 35
  • 32
  • +1 for the railscasts episode. I watched that right after posting this and found it to be really useful! – aarona Feb 02 '11 at 16:57
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.

bobbywilson0
  • 1,072
  • 7
  • 18