Rewrite URI and pass request to the upstream server

Maxim Dounin mdounin at
Tue Mar 17 20:46:50 MSK 2009


On Tue, Mar 17, 2009 at 10:19:58AM -0700, mike wrote:

> On Tue, Mar 17, 2009 at 10:09 AM, Ruben. D. <ruben.grunge84 at> wrote:
> > Hi friends, I need rewrite and old URI and pass the request to the upstream
> > server, here is my current config file:
> >
> >
> > If for example I have I need redirect to
> > and let the upstream process the new
> > request, with my current config I've obtained the rewrite of the URI but
> > nginx return me a 404 error, therefore it is not transfering the request to
> > the upstream server because the 404 error page are different between nginx
> > and my application.
> This is a wild shot but you might try
> - proxy_pass http://mongrel;
> + proxy_pass http://mongrel/;
> I've never used named upstream locations but the ending slash does
> have a different effect when passing HTTP to a backend. I believe it
> maintains the /uri/ request as is, instead of winding up being
> /uri/uri duplicated (I think is the easiest way to explain it?)


Form of proxy_pass with uri component (proxy_pass http://mongrel/) 
changes matched location prefix to this uri component.  So, for 

    location /blah/ {
        proxy_pass http://backend/boom/;

and request "/blah/something" your backend will see 

Without uri component (proxy_pass http://mongrel) uri will be 
transfered to backend as is, i.e. for

    location /blah/ {
        proxy_pass http://backend;

and request "/blah/something" your backend will see 

For location / as you may see from the above form doesn't matter, 

    proxy_pass http://mongrel;
    proxy_pass http://mongrel/;

are equivalent (while the second one will eat a bit more CPU).

Maxim Dounin

More information about the nginx mailing list