2

I recently decided to try out Rails. When working with PHP, I simply had all of my PHP projects in the same directory. For example, I may have http://ubuntu/app1, http://ubuntu/app2, etc.

I created a subdomain for Rails (http://ruby.ubuntu), installed Rails and Passenger and everything is working. However, I may be wrong, but it looks like I can only have one Rails app per subdomain?

My VirtualHost is as follows:

<VirtualHost *:80>
    ServerName ruby.ubuntu
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/ruby/blog/public

    <Directory /var/www/ruby/blog/public>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        RailsEnv development
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

All of my PHP and misc. files are stored in /var/www/main. I want to be able to store all of my Rails apps in /var/www/ruby. I tried changing DocumentRoot to /var/www/ruby, but I don't think it's as simple as that. When I browse to a Rails app's Welcome Aboard page and click on "About my application's environment," I get a 404 page, but when the DocumentRoot is set to the public directory, I get the expected result.

I don't want to have to create a new subdomain every time I create a new project. Is there any way I can make it so I can store all of my apps in /var/www/ruby, and browsing to http://ruby.ubuntu will let me access all of my Rails apps there? That way if I want to create a new app, all I have to do is rails new app, no Apache .htaccess or VirtualHost configuration required.

Derek Maciel
  • 121
  • 1
  • 4
  • possible duplicate of [Multiple Rails sites using Passenger and VirtualHosts?](http://serverfault.com/questions/83288/multiple-rails-sites-using-passenger-and-virtualhosts) – womble Jul 07 '12 at 17:02

3 Answers3

5

you can serve as many rails applications as you wish.

If using apache httpd and passenger, here are the steps:

Just symlink public folder of each of your rails application into apache's DocumentRoot as a subfolder. Then add a RailsBaseURI directive in your apache config that tells passenger that the given folder is a rails application.

Lets say you have two rails apps rapp1 and rapp2. Lets say your apache DocumentRoot is /var/www/html

  ln -s rapp1 /var/www/html/rapp1
  ln -s rapp2 /var/www/html/rapp2

now open your apache virtual host configuration file and add the following two lines

  RailsBaseURI /rapp1
  RailsBaseURI /rapp2

restart your apache server and when you visit http://servername/rapp1, your rails application gets served

Litmus
  • 171
  • 4
0

I could be mistaken but I believe what you're trying to achieve is called Sub-URI's.

Use the ruby.ubuntu subdomain and then each application runs under different /subdirectories.

Some further reading: http://collab.stat.ucla.edu/users/jose/weblog/9e335/

dannymcc
  • 2,677
  • 10
  • 46
  • 72
  • Forgive me if I'm wrong, but doesn't Sub-URI only assign a URI to a folder in the same way that Apache's mod_alias does? Using Sub-URI, I would have to create a new rule for every application. – Derek Maciel Jul 07 '12 at 22:36
0

It looks like you're trying to use SubURIs. Passenger can support them, but you need to tweak your Virtual Host configuration a little.

The Passenger Docs for Apache explain how to do it, along with an example to give you a hand.

qweet
  • 731
  • 5
  • 11