# Nginx location+proxy\_pass in front of multiple mongrel\_clusters?

**URL:** <https://www.ruby-forum.com/t/nginx-location-proxy-pass-in-front-of-multiple-mongrel-clusters/117697>\
**Category:** Deployment\
**Created:** [October 19, 2007, 2:21pm UTC](https://www.ruby-forum.com/t/nginx-location-proxy-pass-in-front-of-multiple-mongrel-clusters/117697 "2007-10-19T14:21:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [October 19, 2007, 2:21pm UTC](https://www.ruby-forum.com/t/nginx-location-proxy-pass-in-front-of-multiple-mongrel-clusters/117697/1 "2007-10-19T14:21:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [October 19, 2007, 4:40pm UTC](https://www.ruby-forum.com/t/nginx-location-proxy-pass-in-front-of-multiple-mongrel-clusters/117697/2 "2007-10-19T16:40:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [October 19, 2007, 5:06pm UTC](https://www.ruby-forum.com/t/nginx-location-proxy-pass-in-front-of-multiple-mongrel-clusters/117697/3 "2007-10-19T17:06:47Z")

</div>

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](http://www.ruby-forum.com/topic/128598)

Regards

David
