Nginx location+proxy_pass in front of multiple mongrel_clusters?

Hi All

I’m trying to move a bunch of rails apps from an apache/fastcgi
platform to nginx/mongrel_cluster.

What I want is something like this;

http://my.server/app1 --> mongrel_cluster1

http://my.server/app2 --> mongrel_cluster2

I can do this in nginx with something like this;

upstream mongrel_cluster1 {
server 127.0.0.1:3001;
server 127.0.0.1:3002;
}

upstream mongrel_cluster2 {
  server 127.0.0.1:4001;
  server 127.0.0.1:4002;
}

server {

location /app1 {
proxy_pass http://mongrel_cluster1;
break;
}

location /app2 {
  proxy_pass http://mongrel_cluster2;
  break;
}

But, the problem is that I’m now hitting my rails apps with paths like
this;

/app1/controller/method

/app2/controller/method

So, I want to use something like this to remove the ‘app1’ part;

rewrite ^/app1/(.*)$ /$1 permanent;

But, that seems to override the proxy_pass directive, because if I put
that in my location blocks, I just get 404 errors, and it’s not
allowed in my upstream blocks.

I know I could use virtual hosts, with a different subdomain for each
app, but that would be this;

http://app1.my.server --> mongrel_cluster1

http://app2.my.server --> mongrel_cluster2

…which is not what I want.

Is there any way to achieve what I want, using nginx?

Thanks in advance for any help.

David

To answer my own post, removing the “permanent” does what I want. i.e.
instead of;

rewrite ^/app1/(.*)$ /$1 permanent;

removing the permanent so that the line reads;

rewrite ^/app1/(.*)$ /$1;

…allows processing to continue to the proxy_pass directive on the
same line.

Cheers

David

To answer my own post again, I must have messed something else up in
my nginx.conf, because a minimal proxy_pass config works fine;

http://www.ruby-forum.com/topic/128598

Regards

David

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs