I'm currently dev开发者_如何学Celoping a user facing web application that gives each new user their own subdomain on the site, which is fine (using subdomain_fu), but is there a way to let a user map their own domain to this subdomain?
I know how to do this manually through SSH-ing into the server and editing the Apache Vhosts file by hand, but is there a way to do this automatically so that a user simply enters their domain into a box on the site (obviously they'd have to change their own DNS elsewhere)?
I'm using Ruby 1.8 and Rails 2.3.3 on top of Apache.
Essentially letting;
http://user.application.com/article-1
be accessed from
http://userdomain.com/article-1
Thanks for any help!
Your users should be able to set up a CNAME record for their domain pointing to your domain, e.g.
userdomain.com. CNAME user.application.com.
and then let your app know that they want to use userdomain.com
as their hostname. I don't think you will have to change your vhost settings because your server will see the request for user.application.com
, but test this by setting up a CNAME of your own to be sure.
In your app you will then need to look at the hostname and if it contains application.com
you do as you do now, but if it doesn't you check to see if there's a user who has set that domain as theirs.
I assume this is just one application that you want users to map different domain names to, right? You shouldn't need to use virtual hosting at all, since all requests will go to the same Rails app, regardless of domain name. If you are using virtual hosting, then the default virtual host (the one that handles http://1.2.3.4 if user.application.com resolved to 1.2.3.4) needs to be your Rails app.
精彩评论