This post shows you how to install/run multiple Rails applications in different subdomains. As always, use these instructions at your own risk and backup everything before.
Assumptions:
- Running the Rails ReadyStack - Ubuntu 8.10, Apache2, Passenger
- Your web server is running with document root at /var/www
- Your Rails apps are in /var/rails
- Your domain is yourdomain.com. Obviously, change it to yours where needed.
Procedure:
Create the first app:
- Go to the rails directory
cd /var/rails - Make a new rails app in /var/rails
rails app1 - Delete the default index file
rm app1/public/index.html - Go to the web server root directory
cd /var/www - Make symbolic links to the app
ln -s /var/rails/app1/public one - Go to the Apache config directory
cd /etc/apache2/sites-available - Create file for app
touch one - Put the following into the file with the editor of your choice
<VirtualHost *:80>
ServerName one.yourdomain.com
DocumentRoot /var/rails/app1/public
</VirtualHost>
- Enable the app.
a2ensite one
This creates a symbolic in sites-enabled to this file.
Create the second app:
- Go to the rails directory
cd /var/rails - Make a new rails app in /var/rails
rails app2 - Delete the default index file
rm app2/public/index.html - Go to the web server root directory
cd /var/www - Make symbolic links to the app
ln -s /var/rails/app2/public two - Go to the Apache config directory
cd /etc/apache2/sites-available - Create file for app
touch two - Put the following into the file with the editor of your choice
<VirtualHost *:80>
ServerName two.yourdomain.com
DocumentRoot /var/rails/app2/public
</VirtualHost>
- Enable the app.
a2ensite two
This creates a symbolic in sites-enabled to this file.
Restart Apache:
/etc/init.d/apache2 reload or /etc/init.d/apache2 restartDisable the default app?
a2dissite defaultUpdate the DNS settings of your webby account:
- Login to webbynode manager
- Select the 'DNS' tab
- Select your domain (or 'New zone' button to create it if it does not exist)
- Click the 'New record' button
- Set 'Type' to "A"
- 'Name' to "one"
- 'Data' to the IP address of your webby
- Leave 'Auxillary Data' and 'TTL' at the defaults.
- Click the 'Save record' button
- Click the 'New record' button
- Set 'Type' to "A"
- 'Name' to "two"
- 'Data' to the IP address of your webby
- Leave 'Auxillary Data' and 'TTL' at the defaults.
- Click the 'Save record' button
That is pretty much it. Work on your apps and browse to them at one.yourdomain.com and two.yourdomain.com.