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 {

upstream mongrel_cluster2 {

server {

location /app1 {
proxy_pass http://mongrel_cluster1;

location /app2 {
  proxy_pass http://mongrel_cluster2;

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



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; --> mongrel_cluster1 --> 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.


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.



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;



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