3

I have a rails application that uses subdomains to allow users to have their own seperate data in a CMS system. Basically a SaaS CMS system like wordpress.com or tumblr.com.

However i would like to give users the ability to choose their own domain (av alias for their subdomain). For example the user henrik.cmsdomain.com would like to have a custom domain that reads henrikswebsite.com.

How can i do this? Do i need to set up my own name servers? I'm not necessarily looking for complete answers, i just don't know where to start.

Im running on an ubuntu 13.10 digitalocean server with nginx, passenger, Rails 4 and postgresql (using schemas to seperate userdata).

Ole Henrik Skogstrøm
  • 6,353
  • 10
  • 57
  • 89

1 Answers1

4

What you're looking for is something called "virtual subdomains" (I think). Here is some information about how to set them up:

You basically need to set up a "wildcard" subdomain in your DNS (which will route all subdomain requests to your app), and let the routing middleware handle the request (& route accordingly)


Domains

Considering the updates, I have had a look online for you:

I don't have experience of this directly, but I'd say you first need to get the domain to point to your site (with CNAME changes). This could then be caught by your routing middleware (as described in the link above), allowing you to "route" the request accordingly

Heroku does this exact thing - it's quite common

Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • I think you missunderstood the question. I got the subdomains working. So the user can visit his own site using chosen_subdomain.officialdoman.com. But i want the user to also be able to choose a apex domain. For example i own example.com and want that to be the domaim for my site "chosen_subdomain.officialdoman.com" – Ole Henrik Skogstrøm Mar 29 '14 at 12:11
  • I don't understand? What you're asking about is still subdomains? I'm looking at this functionality right now too - which is why I'm interested in it :) – Richard Peck Mar 29 '14 at 12:16
  • I'm trying to let the user select their own domain (not just subdomain). Byt lett them use a domain name they own. So i need my application to respond to any domain name and lookup that domain name in a table and then route them to the right user (while maintaining the chosen domain) – Ole Henrik Skogstrøm Mar 29 '14 at 12:22
  • Ohhhhh right, SORRY. I didn't realize you want to do by their own domain. – Richard Peck Mar 29 '14 at 12:22
  • If you are looking for a way to let users selec a subdomain and to seperate the userdata between subdomains (users) you should see this video (this is called a multitenant application):http://railscasts.com/episodes/389-multitenancy-with-postgresql – Ole Henrik Skogstrøm Mar 29 '14 at 12:23
  • Thanks - multi tenancy is the way forward - I wil lwatch that episode, spasibo! – Richard Peck Mar 29 '14 at 12:26
  • 1
    And thank you! The link you gave me to the other question set me on the right path. I have this working in development now :) The good information was under the updated section of the question. – Ole Henrik Skogstrøm Mar 29 '14 at 17:48