Ubuntu - Using mod rails to serve your application

Following from the first article, we now have passenger (mod_rails) installed.

As such, we can move on and create a Ruby on Rails application and see how easy it is to serve using passenger.


Rails application

Move into the public_html folder (if you don't have one, then simply create it):

cd ~/public_html

Then create a simple Ruby on Rails application:

rails testapp


Virtual Host

To serve the Rails application, we need to create a virtual host:

sudo nano /etc/apache2/sites-available/testapp

Although already mentioned, one of the exciting things about mod_rails is that you don't need any special settings in the virtual host configuration.

The contents can be as simple as this:

<VirtualHost *:80>
  ServerName  domain1.com
  ServerAlias www.domain1.com
  DocumentRoot /home/demo/public_html/testapp/public

Of course, you can add custom log file locations and other settings but the main thing to understand is the lack of proxy and port settings.

Once done, we can enable the new site:

sudo a2ensite testapp


As you may know, Rails applications make use of an .htaccess file for various rewrite rules.

If this is a fresh Cloud Server and you do not have the Apache rewrite module enabled, now would be a good time to enable it:

sudo a2enmod rewrite


Finally, restart Apache:

sudo /etc/init.d/apache2 restart

Note: If you get any port and NameVirtualHost errors on reloading Apache, please ensure you read the Apache Virtual Hosts article.


Is that it?

Yup. It really is that simple to serve Ruby on Rails applications with passenger (mod_rails).

Additional Rails apps can be configured in the same way — create a vhost and it's done.

Changes to the application

Whenever you deploy changes to your application all you need to do to is:

touch /home/demo/public_html/testapp/tmp/restart.txt

That will enable the new content to be served — the command can be used in Capistrano or any script you use to deploy your applications.


Phusion's passenger (mod_rails) is easy to install and even easier to use.

There are no ports or proxies or any other complicated configurations — mod_rails offers a great deal to the Ruby on Rails community.

© 2015 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER