Rails & Subdirectories
I spent part of this morning fighting with Rails, trying to get a quick app I wrote hosted below an existing app. It should have been simple, but getting the various pieces cooperating took longer than it should have. The solution is to use the –prefix argument to mongrel_rails. Here’s how I got it going:
Scenario:
RailsApp1 hosted as mysite.com/
RailsApp2 hosted as mysite.com/myapp2
Both apps served via Apache 2.0 + mongrel + pen on Debian Sarge
Scripts:
/etc/init.d/mongrel (customized from Debian’s skeleton)
/etc/mongrel/sites-enabled/myapp1
/etc/mongrel/sites-enabled/myapp2
No need to modify the rails app itself. Some messages I found suggested various mixes of modifying .htaccess and/or the relevant environment.rb files, but that didn’t work for me.
Apache Config:
/etc/apache2/sites-enabled/vhost-mysite.conf:
<VirtualHost *:80> ServerName mysite.comDocumentRoot /srv/www/myapp1Alias /myapp2 /srv/www/myapp2 RewriteEngine On RewriteCond %{REQUEST_URI} ^/myapp2 [NC]RewriteRule ^/.* http://localhost:8850%{REQUEST_URI} [P,QSA] RewriteRule .* http://localhost:8800%{REQUEST_URI} [P,QSA] </VirtualHost>
