Welcome! Log In Create A New Profile

Advanced

Re: Pre-process request via upstream then forward to proxy.

agentzh
May 05, 2011 02:12AM
On Thu, May 5, 2011 at 12:11 PM, AndrewH <nginx-forum@nginx.us> wrote:
> As part of processing a request, I need to first send and receive a
> response to/from an upstream to authenticate some credentials in the
> request.  Once this has been done, the original request needs to be
> proxied to another upstream.
>

Your task can be trivially done in pure Lua by using the ngx_lua
module. Specifically, by using the ngx.location.capture() interface
for Lua to issue your subrequests and wait for the responses.

See http://github.com/chaoslawful/lua-nginx-module for the full documentation.

You can surely code it up in pure C by looking at how ngx_lua does on
the C level. But it's not recommended because it's error prone and the
performance gain is small.

> According to Evan Miller's tutorial, the only valid location for
> spawning sub-requests is in an output filter ie. to post-process a
> response.

Nope, you can surely create subrequests in any of your rewrite,
access, and content phase handlers. That part of Evan Miller's
tutorial is somehow misleading, and keep in mind that Evan stated like
this: "as far as I know..." So he is not to blame ;)

> Does anyone know what the sanctioned way of going about this in NGINX
> is?  Or which existing modules/examples implement similar
> functionality?
>

See the echo_subrequest and echo_location directives provided by ngx_echo:

http://github.com/agentzh/echo-nginx-module

But their (synchronous but non-blocking) subrequest implementation is
not as correct as ngx_lua's.

The ngx_auth_request module by Maxim Dounin is an example of issuing
subrequests in an access phase handler and my ngx_srcache module is
another example for this:

http://github.com/agentzh/srcache-nginx-module

The ngx_eval module is an example of issuing subrequests in a rewrite
phase handler:

http://www.grid.net.ru/nginx/eval.en.html

Happy subrequesting!

-agentzh

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Pre-process request via upstream then forward to proxy.

AndrewH May 05, 2011 12:11AM

Re: Pre-process request via upstream then forward to proxy.

agentzh May 05, 2011 02:12AM

Re: Pre-process request via upstream then forward to proxy.

Maxim Dounin May 05, 2011 02:32AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 203
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready