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:

<pre><br />&lt;VirtualHost *:80&gt;<br /><br />ServerName mysite.com<br />DocumentRoot /srv/www/myapp1<br />Alias /myapp2 /srv/www/myapp2<br /><br />RewriteEngine On<br /><br />RewriteCond %{REQUEST_URI} ^/myapp2 [NC]<br />RewriteRule ^/.* <a href="http://localhost:8850/" title="http://localhost:8850%">http://localhost:8850%</a>{REQUEST_URI} [P,QSA]<br /><br />RewriteRule .* <a href="http://localhost:8800/" title="http://localhost:8800%">http://localhost:8800%</a>{REQUEST_URI} [P,QSA]<br /><br />&lt;/VirtualHost&gt;

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <pre>, <shell>, <c>, <drupal6>, <java>, <javascript>, <objc>, <perl>, <php>, <python>, <rails>, <ruby>, <sql>, <xmlcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.