views:

33

answers:

1

I want to implement something like Tumblr or Wordpress by giving user the option to have their domain name point to their profiles. For instances user go to their domain registrar and the IP of my server so then: www.usersdomain.com will point to www.mysite.com/userid without actually forwarding so that domain name will still show in the address bar.

I wish you can describe the details for steps of doing so.

I'm using Ruby on Rails if that's make a difference. My production environment has Nginx and Passenger.

+2  A: 

My point of view:

  1. Users change DNS records of their sites to point to the IP address of your server. After that operation, every HTTP request to their domains will be "catched" by your IP address and your application (you should reconfigure your HTTP server, however).
  2. Every HTTP request contains the Host header. That header allows us to make such thing as virtual hosting: many and many hosts can point to only one IP;
  3. In your application just extract Host from the request and query your database for user with such host.
  4. Flush contents of his page and that's all.

For example, IP of your service is 100.100.100.100, my domain is redsocks.com. I need to change DNS (an A record) of my domain to point to your IP. Supposedly, I did.

When I point my browser to my domain, the browser makes the following request (or similar) to your own IP, not mine:

GET / HTTP/1.1
Host: redsocks.com
...

Your application has the code (pseudocode) that deals with my request:

user = User.find_by_domain(REQUEST["Host"])
if user == nil
   render_not_found_page
else
   contents = Content.get_contents_of_user(user)
   render_contents_of_user contents 
end

And I see my very own page within your service on my domain.

floatless