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.
Best Answer
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
now open your apache virtual host configuration file and add the following two lines
restart your apache server and when you visit
http://servername/rapp1
, your rails application gets served