# Apache, Mongrel clusters and sub domains

**URL:** <https://www.ruby-forum.com/t/apache-mongrel-clusters-and-sub-domains/144042>\
**Category:** Rails\
**Created:** [July 24, 2008, 9:27pm UTC](https://www.ruby-forum.com/t/apache-mongrel-clusters-and-sub-domains/144042 "2008-07-24T21:27:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmcelhany](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a88e57/32.png) [@bmcelhany](https://www.ruby-forum.com/u/bmcelhany)\
**Post date:** [July 24, 2008, 9:27pm UTC](https://www.ruby-forum.com/t/apache-mongrel-clusters-and-sub-domains/144042/1 "2008-07-24T21:27:05Z")

</div>

There seems to be a ton of documentation out there, but I can’t seem  
to figure out how to get this to work. I’ve got two rails apps: app1,  
which should be available at [http://www.domain.com](http://www.domain.com) and app2 which  
should be available at [http://sub.domain.com](http://sub.domain.com). Both apps should be  
served up by a mongrel cluster (app1 running on ports 8000-8002 and  
app2 running on 9000-9002). App1 is working like a charm, however when  
I go to [http://sub.domain.com](http://sub.domain.com), I get app1 instead of app2. As a side  
note, if I replace app2 with a static html page and take rails/mongrel  
out of the equation entirely, the subdomain works just like it’s  
supposed to.

My gut tells me it’s how I’ve got my virtual host files set up  
(specifically the RewriteCond/RewriteRule parts). Could someone please  
point me in the right direction? Thanks!

-Brian

Physical location:

* * *

app1: /var/www/app1  
app2: /var/www/app2

/etc/apache2/sites-available/default:

* * *

NameVirtualHost \*  
\<Proxy balancer://mongrel\_cluster\>  
BalancerMember [http://localhost:8000](http://localhost:8000)  
BalancerMember [http://localhost:8001](http://localhost:8001)  
BalancerMember [http://localhost:8002](http://localhost:8002)  
  
\<VirtualHost _\>  
ServerName [domain.com](http://domain.com)  
DocumentRoot /var/www/app1/public/  
.  
.  
.  
RewriteEngine On  
RewriteCond %{DOCUMENT\_ROOT}/%{REQUEST\_FILENAME} !-f  
RewriteRule ^/(._)$ balancer://mongrel\_cluster%{REQUEST\_URI}  
[P,QSA,L]

/etc/apache2/sites-available/app2:

* * *

NameVirtualHost \*  
\<Proxy balancer://mongrel\_cluster\>  
BalancerMember [http://localhost:9000](http://localhost:9000)  
BalancerMember [http://localhost:9001](http://localhost:9001)  
BalancerMember [http://localhost:9002](http://localhost:9002)  
  
\<VirtualHost _\>  
ServerName [sub.domain.com](http://sub.domain.com)  
DocumentRoot /var/www/app2/public/  
.  
.  
.  
RewriteEngine On  
RewriteCond %{DOCUMENT\_ROOT}/%{REQUEST\_FILENAME} !-f  
RewriteRule ^/(._)$ balancer://mongrel\_cluster%{REQUEST\_URI}  
[P,QSA,L]

---

<div class="post-metadata">

**Author:** ![bmcelhany](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a88e57/32.png) [@bmcelhany](https://www.ruby-forum.com/u/bmcelhany)\
**Post date:** [July 24, 2008, 10:06pm UTC](https://www.ruby-forum.com/t/apache-mongrel-clusters-and-sub-domains/144042/2 "2008-07-24T22:06:01Z")

</div>

I suspect your problem is that your clusters have the same name. You  
need something more like:

\<Proxy balancer://app1\_mongrel\_cluster\>  
BalancerMember [http://localhost:8000](http://localhost:8000)  
BalancerMember [http://localhost:8001](http://localhost:8001)  
BalancerMember [http://localhost:8002](http://localhost:8002)

\<Proxy balancer://app2\_mongrel\_cluster\>  
BalancerMember [http://localhost:9000](http://localhost:9000)  
BalancerMember [http://localhost:9001](http://localhost:9001)  
BalancerMember [http://localhost:9002](http://localhost:9002)

Then of course update your rewrites to reflect that change.

good luck!  
Tim

---

<div class="post-metadata">

**Author:** ![bmcelhany](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a88e57/32.png) [@bmcelhany](https://www.ruby-forum.com/u/bmcelhany)\
**Post date:** [July 24, 2008, 11:27pm UTC](https://www.ruby-forum.com/t/apache-mongrel-clusters-and-sub-domains/144042/3 "2008-07-24T23:27:42Z")

</div>

Thanks for the quick response Tim! That ended up not being the problem  
but, after making the change you recommended, I stumbled across the  
problem. As I was re-starting both mongrel clusters (just to be on the  
safe side), I received an error that the cluster for app2 couldn’t be  
shut down because of missing PID files. Sure enough, there should have  
been a mongrel.9000.pid, mongrel.9001.pid and mongrel.9002.pid file in  
the app2/tmp/pids directory but they weren’t there. So, even though  
running “mongrel\_rails cluster::start” seemed to be correctly starting  
the cluster, in actuality, nothing was starting.

It turns out that somehow those files got deleted while the cluster  
was still running. I needed to manually kill the process on the server  
and then re-start the mongrel cluster for app2. Everything’s working  
like a charm now.

-Brian
