Topic: Hosting more than one rails app

Currently I've got one rails app running using mongrel and apache 2. This works fine. Trying to get two running seems problematic.

I use the following virtual host configuration, and while each website works fine on it's own, when I try to run both they seem to turn into a horrible hybrid website using files from each i.e they might try and use each others css files.

#################
# RAILS HOSTING #
#################

<Proxy balancer://mongrel_cluster>
    BalancerMember http://127.0.0.1:8000
    BalancerMember http://127.0.0.1:8001
</Proxy>

#carolineede.com
<VirtualHost 81.171.111.167>
    ServerName www.carolineede.com
    DocumentRoot /var/www/localhost/htdocs/carrie/current/public

    <Directory "/var/www/localhost/htdocs/carrie/current/public">
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

    RewriteEngine On

    # Check for maintenance file and redirect all requests
    RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteRule ^.*$ /system/maintenance.html [L]

    # Rewrite index to check for static
    RewriteRule ^/$ /index.html [QSA]
    # Rewrite to check for Rails cached page
    RewriteRule ^([^.]+)$ $1.html [QSA]
    # Redirect all non-static requests to cluster
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]

</VirtualHost>


#yumc.co.uk
<Proxy balancer://mongrel_cluster>
    BalancerMember http://127.0.0.1:8002
    BalancerMember http://127.0.0.1:8003
</Proxy>

<VirtualHost 81.171.111.167>
    ServerName www.yumc.co.uk
    DocumentRoot /var/www/localhost/htdocs/yumc/current/public

    <Directory "/var/www/localhost/htdocs/yumc/current/public">
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

    RewriteEngine On

    # Check for maintenance file and redirect all requests
    RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteRule ^.*$ /system/maintenance.html [L]

    # Rewrite index to check for static
    RewriteRule ^/$ /index.html [QSA]
    # Rewrite to check for Rails cached page
    RewriteRule ^([^.]+)$ $1.html [QSA]
    # Redirect all non-static requests to cluster
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
</VirtualHost>


I'm not sure if it is something obvious with the Vhost configuration or a limitation of mongrel...

Are there any multi rails app hosting guides out there?

carrie's and yumc's mongrel_cluster.yml respectfully:

cwd: /home/carrie/www/current
port: "8000"
environment: production
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 2

user: mongrel
cwd: /home/yumc/www/current/
log_file: log/mongrel.log
port: "8002"
environment: production
group: mongrel
address: 127.0.0.1
pid_file: tmp/pids/mongrel.pid
servers: 2

Re: Hosting more than one rails app

You need to call your proxies different names:

<Proxy balancer://carrie>
...
<Proxy balancer://yumc>

and then:
RewriteRule ^/(.*)$ balancer://carrie%{REQUEST_URI} [P,QSA,L]
...
RewriteRule ^/(.*)$ balancer://yuml%{REQUEST_URI} [P,QSA,L]

Re: Hosting more than one rails app

Aaah. Brilliant. Thanks.

Re: Hosting more than one rails app

btw have you tried Phusion passenger.
That would make your life much easier.

Austin Web Developer
Web Application Development with Ruby on Rails, PHP (w CakePHP or CodeIgniter), ASP.NET (w MVC)