Catch ALL requests by LUA-script

agentzh agentzh at gmail.com
Tue Mar 1 14:11:25 MSK 2011


On Tue, Mar 1, 2011 at 5:53 PM, andiL <nginx-forum at nginx.us> wrote:
> Thanks for your answer.
>
> I just figured out, that "location ~ { ...}" will catch all requests,
> too

Once a location gets matched, it'll be difficult to persuade nginx to
match against other locations because a hit is already made.

>
> I just have one more question:
>
> What would be the best phase-handler to check/manipulate http-requests
> and http-responses?
>
> LUA can work with rewrite (URI transformation on location level), access
> (access restrictions check), content (generating content for output) and
>  - as i understand - these are processed by nginx in this given order.
>

Another difference between rewrite phase handlers and access phase
handlers is that access phase is skipped completely for subrequests
while rewrite phase handlers will be run even in a subrequest.

> Theoretically the best would be to get in directly in the begining with
> rewrite_by_lua(_file) to be able to check/manipulate request-headers,
> request-body, etc.?
>

access_by_lua(_file) is fine too :)

> But nginx will still output it's "default content" after that...

Sure.

> Is there any chance LUA can have access to all of the HTTP-Response, too
> (especially the headers - the content is not that important at the
> moment)?
>

This is exactly what output filters are for ;)

For now, ngx_lua does not provide output filter hooks like
output_header_filter_by_lua(_file) and
output_body_filter_by_lua(_file). But these are on our TODO list. And
as always: patches welcome, and volunteers welcome!

> I know that it can be done via ngx.headers["HEADER"] but i don't think
> this will be possible when still working in the rewrite/access phase?
>

No, the rewrite and access phases are just too early :)

> Hope i don't understand something very wrong there :)
>

Almost right :)

Cheers,
-agentzh



More information about the nginx mailing list