Nginx, mongrel_cluster, multiple virtual hosts pointing to one application but each to a different

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 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 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

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


Aníbal

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 domain1.com;

then in the location portion:
if (!-f $request_filename) {
proxy_pass http://mongrel;
break;
}

And my other domain has the following:
server_name www.myblog.com myblog.com;

then in the location portion:
if (!-f $request_filename) {
rewrite ^/ /blog break;
proxy_pass http://mongrel;
break;
}

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

Thanks,

Raul

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


Aníbal