# Deploying Lots of Rails Apps to the Same Domain

**URL:** <https://www.ruby-forum.com/t/deploying-lots-of-rails-apps-to-the-same-domain/103881>\
**Category:** Deployment\
**Created:** [May 11, 2007, 7:35am UTC](https://www.ruby-forum.com/t/deploying-lots-of-rails-apps-to-the-same-domain/103881 "2007-05-11T07:35:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 11, 2007, 7:35am UTC](https://www.ruby-forum.com/t/deploying-lots-of-rails-apps-to-the-same-domain/103881/1 "2007-05-11T07:35:24Z")

</div>

Hi. I have a dedicated server (linux / rails / mongrel) that I’m  
deploying to. I am able to deploy different applications to different  
domains/subdomains just fine using the standard rails / mongrel /  
apache config (as instructed from agile web second edition).

However, the kink is I need to deploy lots of rails applications under  
the same domain. The reason for this is the applications need to be  
directly callable from the parent application (at the root domain) via  
AJAX so they need to be on the same domain. Calling an ajax request on  
sub-domains fail. I know there are a bunch of javascript hacks, but  
for now I’d like to just deploy the apps to the same domain (using  
virtual folders to identify them).

Here is what I’m after:

http://[domain] → Rails Parent App (mongrel ports 8000-8001)  
http://[domain]/app1/ → Rails Child App 1 (mongrel ports 8010-8011)  
http://[domain]/app2/ → Rails Child App 2 (mongrel ports 8020-8021)  
etc…

The mongrel instances are set up fine for all my apps. I just need to  
fix up the mod\_rewrite in order to forward the requests based on  
folder name to different mongrel instances. I don’t mind putting the  
child app names and paths statically into the config for now.

What I have tried so far is using a rewrite rule that picks the  
http://[domain]/app1/[rails path] and forwards it to the mongrel  
cluster defined by app1\_cluster.  
RewriteRule ^/(._)/app1/(._)$ balancer://app1\_cluster%{REQUEST\_URI}  
[P,QSA,L]

Needless to say, it doesn’t work. I don’t think the RewriteRule is  
being hit because I cant get the /app1/ requests to hit the right  
mongrel cluster. All I get is 404s. The parent rails app works fine at  
the root of the domain. I’m guessing my RewriteRule is probably way  
off.

Thanks in advance for any help you can offer.

-Jacques  
removed\_email\_address@domain.invalid

## Here is my full apache virtual server config file. Its mostly standard issue from: [http://mongrel.rubyforge.org/docs/apache.html](http://mongrel.rubyforge.org/docs/apache.html)

\<VirtualHost 211.149.251.41\>  
ServerName [dev.you-comics.com](http://dev.you-comics.com)

DocumentRoot /var/www/apps/youcomics/current/public

\<Directory “/var/www/apps/youcomics/current/public”\>  
Options FollowSymLinks  
AllowOverride None  
Order allow,deny  
Allow from all

# Configure Mongrel Cluster

\<Proxy balancer://youcomics\_cluster\>  
BalancerMember [http://127.0.0.1:8010](http://127.0.0.1:8010)  
BalancerMember [http://127.0.0.1:8011](http://127.0.0.1:8011)

\<Proxy balancer://app1\_cluster\>  
BalancerMember [http://127.0.0.1:8020](http://127.0.0.1:8020)  
BalancerMember [http://127.0.0.1:8021](http://127.0.0.1:8021)

RewriteEngine On

# Prevent access to .svn directories

RewriteRule ^(.\*/)?.svn/ - [F,L]  
ErrorDocument 403 “Access Forbidden”

# 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

#app1  
RewriteRule ^/(._)/app1/(._)$ balancer://app1\_cluster%{REQUEST\_URI}  
[P,QSA,L]

#main dashboard  
RewriteRule ^/(.\*)$ balancer://youtcomics\_cluster%{REQUEST\_URI}  
[P,QSA,L]

# Deflate

AddOutputFilterByType DEFLATE text/html text/plain text/xml  
BrowserMatch ^Mozilla/4 gzip-only-text/html  
BrowserMatch ^Mozilla/4.0[678] no-gzip  
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

ErrorLog logs/youcomics.com-error\_log  
CustomLog logs/youcomics.com-access\_log combined

-----

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 11, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/deploying-lots-of-rails-apps-to-the-same-domain/103881/2 "2007-05-11T23:51:34Z")

</div>

I do something similar. I can’t really help you with the  
mod\_proxy\_balance part as I’m using Apache 2.0. Here’s how I run it;

Apache → nginx → mongrel\_cluster  
each nginx/mongrel stack has a port different port and I spawn the  
mongrels with the --prefix=/foo option.

Apache mod\_proxy looks like this  
ProxyPass /app1/ [http://hostname:8000/app1/](http://hostname:8000/app1/)  
ProxyPassReverse [http://hostname:8000/app1/](http://hostname:8000/app1/) /app1/

ProxyPass /app2/ [http://hostname:8100/app2/](http://hostname:8100/app2/)  
ProxyPassReverse [http://hostname:8100/app2/](http://hostname:8100/app2/) /app2/

et al.

I don’t use an application bound to / just a static landing page for  
simplicity and speed.

hope this helps or at least gives you a direction to try…

–R
