Idan Arye
Idan Arye

Reputation: 12603

Multiple sites in multiple projects on the same rails server

I've searched the web, but I can only find information on sharing code between multiple sites and on separating the database to isolated models. This is not what I want.

I want to run a single rails server, with a single DNS address and a single port - http://myportal.com - that will handle several other sites - http://myportal.com/site1, http://myportal.com/site2 etc.

I want each site to have it's own folder(and SCM repository), it's own database, it's own routing - it's own everything. That is - I want to be able to develop each site as a standalone - that means I need to be able to run site1 site as http://localhost:3000 and not http://localhost:3000/site1.

On the server, the root site(the one that responds to the http://myportal.com address should be the one I run the server from, and it should know the absolute paths of the other sites(which will be in different directories on the server, not in child directories of the root site) and provide routing information for them - but it should also chain to the other sites routes.rb files. That means that if I go to address http://myportal.com/site1/books/ the root site should handle http://myportal.com/site1, and site1 should handle /books/. The root site should not need to know about the other sites' internal routing structures.

Is this possible? Right now I'm running the rails server that comes with the gem(rails server from the command line) on a Windows Server 2008 server, but I'm willing to install another server if that's what needed to accomplish the goal I described.

Thanks in advance!

Upvotes: 4

Views: 1104

Answers (2)

dinnouti
dinnouti

Reputation: 1796

Create a symlink:

cd ~/Sites
ln -s /Users/hg/Developer/Rails/railsproj1/public ./railsproj1

modify apache config file

<VirtualHost *:80>
  ServerName localhost
  DocumentRoot /Users/hg/Sites
  <Directory /Users/hg/Sites>
    AllowOverride All
    Options Indexes FollowSymLinks MultiViews
    Order allow,deny
    Allow from all
  </Directory>
  RailsBaseURI /railsproj1
  RailsEnv development
</VirtualHost>

Answer source: http://collab.stat.ucla.edu/users/jose/weblog/9e335/

Upvotes: 0

tadman
tadman

Reputation: 211570

You should be able to do this with Apache or nginx and possibly IIS if configured correctly. I'm most familiar with Apache and the flexible mod_rewrite and mod_proxy components that can facilitate this.

The idea is you rewrite http://example.com/ to be http://example.com:3000/ and http://example.com/site2 as http://example.com:3001/site2 and so forth.

It's also possible to do this with Passenger and some clever use of the VirtualHost directive, but you may have to fiddle to get a configuration that works for you. Remember that rewriting the headers to route internally has no effect on the resulting HTML your servers emit.

Upvotes: 1

Related Questions