Multiple domain name, One Rails application, is this possibl


#1

Hello folks,
I’m new to the Rails framework and don’t know where to look to find my
answer.

Here is the question, Is there a way to set multiple domain name for a
rails application, and base on the URL do the work in the app.
Imagine I have a user based document management system, each user want
to
access to her docs using her domain, but I don’t like to have many rails
app
just for multiple domains, is there a way to show the users’ docs base
on
the URL?

Any pointer to any book, article or direct answer is extremely
appreciated.

Thanks in advance,
Dunnil


#2

Yes, I’m doing this with my sites (e.g., aspectprogramming.com and
links therein). My sites are all registered to go the same IP address
and my ApplicationController (application.rb) defines a
“before_filter” method that looks at the value of “request.host” to
determine which site the user is on.

A tricky bit is testing locally, e.g., “localhost:3000” obviously
isn’t the same as “myvanitysite.com”. To support this, you can add
some development hooks, like a special request parameter or
environment variable to force the one you want. Another possibility is
to define another configuration (in addition to the usual “test”,
“production”, etc.) A disadvantage of this approach is that you won’t
be able to surf between “fake” domains, as only one will be supported
at a time.

By the way, I also run typo as a separate application. I handle this
through the lighttpd configuration, as described in numerous places on
the web.

Hope this helps.

dean


Dean W.
http://www.aspectassoc.com
http://www.aspectprogramming.com
http://www.contract4j.org


#3

For testing purposes, you can ‘fake’ various domain names to point at
your local server. The domains can be real or fake domain names, and
all should be pointed at the “localhost” ip address (127.0.0.1).

On *nix & Mac OS X, edit the /etc/hosts file. E.g.:
127.0.0.1 my.example.tld
127.0.0.1 another.test.tld
127.0.0.1 etc.domain.tld

On Mac OS X, there are a couple extra steps. First, in the terminal,
run the command:
sudo niload -v hosts . < /etc/hosts
That will copy the hosts into NetInfo.

You probably also need to add the hosts as ‘machines’ in NetInfo,
too. For each host:
sudo niutil -create / /machines/my.example.tld
sudo niutil -createprop / /machines/my.example.tld ip_address
127.0.0.1

With that, you’ll be able to access a server running on your system
with any of the domain names you used.

Note that doing the above prevents you from accessing the actual
servers at those domains if they are real domains on other computers.
So, don’t forget to roll that stuff back later!

To roll back:

Delete or comment-out the domains you added in the /etc/hosts file.

On Mac OS X, you can use the NetInfo Manager application
(/Applications/Utilities/NetInfo Manager) to delete the appropriate
entries from the “machines” directory. (Be sure to not mess with the
“localhost” entry, though.)


#4

If you want to do the same thing under Windows XP, run (Start -> Run)

notepad C:\WINDOWS\system32\drivers\etc\hosts

The file you’ll see works excatly like its *nix counterparts.


#5

Hi, I’m newbie and facing this situation too. I have several questions:

  1. can www.a.com and www.b.com point to the same
    [app]/controller/application.rb ?

  2. can www.a.com/another/controller and www.b.com/another/controller
    point to the same [app]/controller/another/controller.rb ? or should
    they point to [app]/controller/domain_controler/another/controller.rb ?

  3. i’m a beginner in using cpanel. can this domain management thing be
    done with cpanel? – and which one should i use, the ‘addon domain’
    menu, or ‘parked domain’ menu?

thanks in advance

kind regards,

Adrian L.


#6

Grant Neufeld wrote:

the command:
I don’t have to do any of these extra steps on Mac OS X 10.4.6.

sudo niload -v hosts . < /etc/hosts

According to man niload

Most processes on Mac OS X access the information from the files in
/etc and from NetInfo indirectly through the system library and the
lookupd daemon. In some cases the files in /etc are consulted before
NetInfo, making it unnecessary to copy information from these files
into NetInfo. The files /etc/hosts, /etc/networks, /etc/services,
/etc/protocols, and /etc/rpcs are consulted before NetInfo.

Editing /etc/hosts is much simpler. Rolling back is simpler also.

Ray


#7

On Apr 13, 6:23 am, Adrian L. removed_email_address@domain.invalid
wrote:

done with cpanel? – and which one should i use, the ‘addon domain’
menu, or ‘parked domain’ menu?

thanks in advance

kind regards,

Adrian L.


Posted viahttp://www.ruby-forum.com/.

google for subdomains and account keys:
http://cleanair.highgroove.com/articles/2006/08/14/simplied-subdomain-authentication-in-ruby-on-rails
http://wiki.rubyonrails.com/rails/pages/HowToUseSubdomainsAsAccountKeys

http://dev.rubyonrails.org/svn/rails/plugins/account_location/README


#8

removed_email_address@domain.invalid wrote:

google for subdomains and account keys:
http://cleanair.highgroove.com/articles/2006/08/14/simplied-subdomain-authentication-in-ruby-on-rails
http://wiki.rubyonrails.com/rails/pages/HowToUseSubdomainsAsAccountKeys

http://dev.rubyonrails.org/svn/rails/plugins/account_location/README

thanks for your kind reply

I’ve successfully used SubdomainAsAccountKeys in my previous
application.
but it is not what I’m trying to do now

if SubdomainAsAccountKeys give the user a subdomain account, what I am
trying to do now is to give the user a domain account.

I’ve tried to google for this problem previously, and google lead me to
this page :slight_smile:

enlighten me please,

Adrian L.


#9

Thank you very much, that’s just what I need.
I hope my webhost company will give me the access to apache’s
ServerAlias :slight_smile:

Peter De Berdt wrote:

http://httpd.apache.org/docs/1.3/mod/core.html#serveralias


#10

Chances are that the add-on domain option in cpanel actually adds
this line to the apache config file.

On 14 Apr 2007, at 01:51, Adrian L. wrote:

Thank you very much, that’s just what I need.
I hope my webhost company will give me the access to apache’s
ServerAlias :slight_smile:

Peter De Berdt wrote:

http://httpd.apache.org/docs/1.3/mod/core.html#serveralias

Best regards

Peter De Berdt


#11

On 13 Apr 2007, at 16:49, Adrian L. wrote:

enlighten me please,

What you need to do if you want to host the same application on two
domain names, is put a ServerAlias in the Apache config file. That
way, both (or more than two) domain names will point to the same
application.

http://httpd.apache.org/docs/1.3/mod/core.html#serveralias

Best regards

Peter De Berdt


#12

You might also want to look at any options on there concerning
“mirroring”.
I’m currently using such a setup to serve multiple sites out of one app.

RSL