# Multiple Rails apps within one Apache VirtualHost

**URL:** <https://www.ruby-forum.com/t/multiple-rails-apps-within-one-apache-virtualhost/132269>\
**Category:** Rails\
**Created:** [March 18, 2008, 4:25pm UTC](https://www.ruby-forum.com/t/multiple-rails-apps-within-one-apache-virtualhost/132269 "2008-03-18T16:25:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [March 18, 2008, 4:25pm UTC](https://www.ruby-forum.com/t/multiple-rails-apps-within-one-apache-virtualhost/132269/1 "2008-03-18T16:25:28Z")

</div>

Has anyone configured multiple Rails apps within the same VirtualHost  
directive? I need to do this with the apps selected by the initial  
path. I’m using Apache 2.2.3 with mod\_proxy\_balancer and Rails 2.0.2.

In fact, non-Rails apps have to be configured within this VirtualHost  
also, but that problem has been solved via a Location directive. I  
tried a similar Location statement for the Rails apps with no success  
yet, so I thought I’d see if anyone has already done this. To date,  
I’ve only needed to configure one Rails app within a VirtualHost with  
what appears to be a fairly typical config.

Any info sources for more advanced Apache configuration for Rails  
would be appreciated.

Brian A.

---

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [March 18, 2008, 4:53pm UTC](https://www.ruby-forum.com/t/multiple-rails-apps-within-one-apache-virtualhost/132269/2 "2008-03-18T16:53:29Z")

</div>

Brian,

I would look at using mod\_proxy to send different URLs to your rails  
apps if you need to do in one virtual host. You would start each app  
with mongrel\_rails on X port and then config Apache like so:

#mongrel rails app#1 running on 3000  
ProxyPass /yourapp\_prefix http://:3000  
ProxyPassReverse /yourapp\_prefix http://:3000

#mongrel rails app#1 running on 3001  
ProxyPass /yourapp2\_prefix http://:3001  
ProxyPassReverse /yourapp2\_prefix http://:3001

The real issue you will run into with a VPS is memory usage. Some VPSs  
will kill your mongrel’s if they hog resources. So you’ll want to also  
run a cron script or “monit” to keep an eye on them.

---

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [March 18, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/multiple-rails-apps-within-one-apache-virtualhost/132269/3 "2008-03-18T17:18:53Z")

</div>

On Mar 18, 11:52 am, blasterpal [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Brian,
> 
> I would look at using mod\_proxy to send different URLs to your rails  
> apps if you need to do in one virtual host. You would start each app  
> with mongrel\_rails on X port and then config Apache like so:
> 
> #mongrel rails app#1 running on 3000  
> ProxyPass /yourapp\_prefix http://:3000  
> ProxyPassReverse /yourapp\_prefix http://:3000

I’ve seen some folks using the above (ProxyPass ProxyPassReverse), and  
others using the following (RewriteRule). Any advantages of one over  
the other?

# Redirect all non-static requests to cluster

RewriteCond %{DOCUMENT\_ROOT}/%{REQUEST\_FILENAME} !-f  
RewriteRule ^/app1(._)$ balancer://cluster1%{REQUEST\_URI} [P,QSA,L]  
RewriteRule ^/app2(._)$ balancer://cluster2%{REQUEST\_URI} [P,QSA,L]

> #mongrel rails app#1 running on 3001  
> ProxyPass /yourapp2\_prefix http://:3001  
> ProxyPassReverse /yourapp2\_prefix http://:3001
> 
> The real issue you will run into with a VPS is memory usage. Some VPSs  
> will kill your mongrel’s if they hog resources. So you’ll want to also  
> run a cron script or “monit” to keep an eye on them.

This is on a dedicated machine, not a VPS. The reason I need multiple  
Rails apps configured in the same VirtualHost is because we’re already  
using the host name for another purpose - to identify an  
organization. We’ve specified a \* wildcard DNS entry to allow  
handling any number of hosts (the apps will parse the hostname to  
determine organization). For example:

http://.foo.com/rails1/controller/action/…  
http://.foo.com/rails2/controller/action/…  
http://.foo.com/nonrails1/…  
http://.foo.com/nonrails2/…

The apps are written by one company and cooperate, but also have a  
degree of independence. I’d prefer to have each app provide its own  
location for static files for Apache to serve directly, so I think my  
main problem is finding a nice way to have the equivalent of a docroot  
per app. I could probably live with a solution that requires the rails  
app to share a directory tree - maybe via soft links.

---

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [March 18, 2008, 10:31pm UTC](https://www.ruby-forum.com/t/multiple-rails-apps-within-one-apache-virtualhost/132269/4 "2008-03-18T22:31:01Z")

</div>

On Mar 18, 11:24 am, Brian A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Has anyone configured multiple Rails apps within the same VirtualHost  
> directive? I need to do this with the apps selected by the initial  
> path. I’m using Apache 2.2.3 with mod\_proxy\_balancer and Rails 2.0.2.

The following solution seems to work fairly well for me so far:

> **[Multiple Ruby on Rails apps with Mongrel and Apache](http://tonyrose023.blogspot.com/2007/01/multiple-rails-apps-with-mongrel.html)**
>
> This post will show how to deploy multiple Ruby on Rails applications using Apache2.2 and Mongrel Clusters. The goal is to serve many apps ...

I had to mess around with some additional RewriteRules to get Apache  
to serve static files instead of mongrel and to deal with Rails  
caching.
