Nginx for proxy + rewrite

Pavel Georgiev pavel at netclime.com
Wed Feb 27 23:27:18 MSK 2008


On Wednesday 27 February 2008 21:08:45 Igor Sysoev wrote:
> On Wed, Feb 27, 2008 at 08:30:47PM +0200, Pavel Georgiev wrote:
> > I`ve beed using nxingx as a local balancer for few backend servers:
> >
> >
> > http {
> >    upstream mydomain.com {
> >       server 192.168.8.30; # backend server
> >    }
> >    server {
> >       listen       192.168.10.1:8080;
> >       server_name  cmydomain.com;
> >
> >       location / {
> >          proxy_pass           http://mydomain.com;
> >          proxy_redirect       off;
> >          proxy_set_header     Host $host;
> >       }
> >    }
> > }
> >
> >
> > What I need to do is for a certain url to rewrite it to an external url
> > but serve the requests as a proxy instead of returing a redirect, so this
> > is transparent to the client:
> >
> > http://mydomain.com/redirect/(.*)$ should go to
> > http://extranal.comain.com/$1
> >
> > I saw this is possible with a simple rewrite but it returns a redirect to
> > the client. Is is possible to make nginx to server the rewrite as a
> > proxy?
>
> Or probably, you need X-Accel-Redirect:
>
> http://wiki.codemongers.com/NginxXSendfile

What I`m trying to do is to server some location  (/redirect/ in the example 
above) to an external server. It is doable with this:

location /redirect {
   rewrite ^/redirect/(.*)$       http://some.domain.com/$1
}

This however returns a 302 code, what I want is nginx to get the file 
requested from http://some.domain.com/ and server it to the client, so that 
the client doesn't have a clue that this was taken from an external server. 
In other words, I`d like to treat http://some.domain.com as a backend server, 
but just for a given location.

Hope that makes sense. I don't think X-Accel-Redirect is what I need here.





More information about the nginx mailing list