# Nginx, mongrel\_cluster, multiple virtual hosts pointing to one application but each to a different

**URL:** <https://www.ruby-forum.com/t/nginx-mongrel-cluster-multiple-virtual-hosts-pointing-to-one-application-but-each-to-a-different/129240>\
**Category:** Deployment\
**Created:** [February 15, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-cluster-multiple-virtual-hosts-pointing-to-one-application-but-each-to-a-different/129240 "2008-02-15T18:06:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roller8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47774/32.png) [@roller8](https://www.ruby-forum.com/u/roller8)\
**Post date:** [February 15, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-cluster-multiple-virtual-hosts-pointing-to-one-application-but-each-to-a-different/129240/1 "2008-02-15T18:06:47Z")

</div>

Hi all,

I have one rails app running on this setup:

- Centos
- nginx
- a mongrel\_cluster

Setting up virtual hosts with nginx is easy enough, but I’d like to  
point different hosts to different controllers. For example, I have  
[http://www.domain1.com](http://www.domain1.com) which follows the normal index routing and goes  
to a controller named ‘controller1’ according to my Rails routes and  
works perfectly. But I also have [http://www.domain2.com](http://www.domain2.com) and I’d like  
this to go to a controller named ‘controller2’. This way I would have  
one app, same site, but different landing pages depending on which  
domain name you use to visit the site.

I already tried the request\_routing plugin by Dan W. which lets me  
handle all of this right in the Rails routes, which I love and works  
great, but I imagine it has to be a performance hit. This site will  
have thousands of visitors a day so performance is a concern.

Thanks in advance for any suggestions/recommendations.

Raul

---

<div class="post-metadata">

**Author:** ![roller8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47774/32.png) [@roller8](https://www.ruby-forum.com/u/roller8)\
**Post date:** [February 16, 2008, 3:21pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-cluster-multiple-virtual-hosts-pointing-to-one-application-but-each-to-a-different/129240/2 "2008-02-16T15:21:29Z")

</div>

Umm, you need to add rewriting so both requests get mapped to the  
differente controllers…

–  
Aníbal

---

<div class="post-metadata">

**Author:** ![roller8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47774/32.png) [@roller8](https://www.ruby-forum.com/u/roller8)\
**Post date:** [February 18, 2008, 7:19pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-cluster-multiple-virtual-hosts-pointing-to-one-application-but-each-to-a-different/129240/3 "2008-02-18T19:19:01Z")

</div>

OK thanks. That was just the little clue I needed to look at the  
correct documentation for nginx. What I ended up with was the  
following:

My primary domain has this in it’s server portion:  
server\_name [www.domain1.com](http://www.domain1.com) [domain1.com](http://domain1.com);

then in the location portion:  
if (!-f $request\_filename) {  
proxy\_pass [http://mongrel](http://mongrel);  
break;  
}

And my other domain has the following:  
server\_name [www.myblog.com](http://www.myblog.com) [myblog.com](http://myblog.com);

then in the location portion:  
if (!-f $request\_filename) {  
rewrite ^/ /blog break;  
proxy\_pass [http://mongrel](http://mongrel);  
break;  
}

Just a single rewrite line to append the controller name to the  
original url request.

Thanks,

Raul

---

<div class="post-metadata">

**Author:** ![roller8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47774/32.png) [@roller8](https://www.ruby-forum.com/u/roller8)\
**Post date:** [February 19, 2008, 12:04pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-cluster-multiple-virtual-hosts-pointing-to-one-application-but-each-to-a-different/129240/4 "2008-02-19T12:04:09Z")

</div>

You are welcome, as you said it was just a little pointer.

–  
Aníbal
