further "Hacking" the event model of Nginx

Maxim Dounin mdounin at mdounin.ru
Sat Jul 17 10:57:09 MSD 2010


Hello!

On Fri, Jul 16, 2010 at 10:41:11AM +0200, Vincent Huang wrote:

> Johan Bergström wrote:
> > Hello,
> > 
> > On 16 jul 2010, at 09.33, Vincent Huang wrote:
> > 
> >> Thanks for your help.
> >> I need hold the response from one backend and send it to another(not 
> >> directory use the backed response as the result to client), so I have to 
> >> write some code inside nginx....
> >> Thanks again;-)
> > 
> > The example might be a bit misleading in your case. What 
> > X-Accel-Redirect does is take precedence over the location uri. You 
> > don't specifically have to pass the location match to a directory for 
> > downloads, you might just as well pass it along to another backend.
> > 
> > This is how my setup looks like:
> >  - incoming get /foo
> >  - location match on /foo that passes to fcgi backend
> >  - fcgi backend analyzes request and returns response with 
> > x-accel-redirect /backend1/foo
> >  - location match on /backend1 passes the request along to http backend
> >  - backend responds with "final" request, master sends back to client
> 
> 
> X-Accel-Redirect only works for intern redirect(just like what 
> ngx_http_subrequest(...)). My backend is another remote server(it should 
> like what ngx_http_upstream_t done in proxy/fcgi module).
> Thanks for your help;-)

Yes, X-Accel-Redirect does internal redirect.  No, internal 
redirects isn't limited to local files, they may be easily handled 
by proxy/fastcgi modules as well.  E.g. in configuration like 
this:

    location /back1 {
        proxy_pass http://back1;
    }

    location /back2 
        proxy_pass http://back2;
    }

backends may easily bounce request from one to another via 
X-Accel-Redirect.

Maxim Dounin



More information about the nginx mailing list