nginx location+proxy_pass?

David Salgado david at
Fri Oct 19 17:20:27 MSD 2007

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



...when the apps want the paths to be just /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; --> 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.


More information about the nginx mailing list