Super easy SUB-URI hosting with mod_rails

With an Amazon EC2 instance up, next very obvious task was to get the hosting up. Objective was to host static content along with multiple Rails apps on the same EC2 instance. Purists might not agree to this, but getting up and running was the first target.

Apache is configured with DocumentRoot as /mnt/app/shared

My Rails apps live inside /mnt/app/releases/<app_name>/<app_dir_structure>

<app_name_1> should be exposed as http://blah-blah.com/dev

/etc/apache2/sites-available/ looks like

<VirtualHost *:80>
DocumentRoot /mnt/app/shared
RailsBaseURI /dev
</VirtualHost>

<VirtualHost *:80>

DocumentRoot /mnt/app/shared

RailsBaseURI /dev

</VirtualHost>

(This is important)
Inside the /mnt/app/shared directory, my /dev symlink now points to /mnt/app/releases/<app_name_1>/public

And inside my <app_name_1>/config/environment.rb, just before the Initializer block ends, add

config.action_controller.relative_url_root = "/dev"

And you’r done! Touch the <app_name_1>/tmp/restart.txt file and reload your app in the browser! It should be running!

Some excellent material to read before attempting this…

Oh yeah, the AMI being used is Webficient’s Ubuntu 8.04 image, with Rails 2.3.2, passenger, etc etc.

Next target – move over the configuration to Puppet!

Good Luck :)

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

  • http://www.apnabill.com Mayank Jain (makuchaku)

    Another issue I ran into was the production logs not being written to /log/production.log

    Reason/Solution – `chmod 0666 log/production.log`

    mod_rails runs the app with the user’s permission who owns the config/environment.rb file. Make sure the permissions and ownership is correct. More details at mod_rails apache docs.