Catch ALL requests by LUA-script

agentzh agentzh at
Tue Mar 1 11:38:55 MSK 2011

On Tue, Mar 1, 2011 at 3:34 PM, andiL <nginx-forum at> wrote:
> What i would like to to:
> Is it possible to create a location-entry in the nginx.conf that ALL
> requests coming to the Server are handled by a LUA-script?

I've just allowed use of rewrite_by_lua_file (and its friends) at the
server and http block levels in ngx_lua's git master HEAD ( ).

Here's a small example from the ngx_lua test suite:

    server {
        listen          1984;
        server_name     'localhost';

        location / {
            root html;
            index index.html index.htm;

        access_by_lua 'ngx.header["X-Foo"] = "bar" ngx.send_headers()';


    curl -i localhost:1984/


    HTTP/1.1 200 OK
    Server: nginx/0.8.54 (without pool)
    Date: Tue, 01 Mar 2011 08:34:45 GMT
    Content-Type: text/plain
    Transfer-Encoding: chunked
    Connection: keep-alive
    X-Foo: bar

    <html><head><title>It works!</title></head><body>It works!</body></html>

This is just for demonstration purposes, blindly sending headers
directly from within an access or rewrite handler is usually
considered bad practice ;)

> i.e. i have set the *.php and / locations to internal so only the lua
> script should have access to the files (it's responsible for the in- and
> output)

Well, you do not need an ad-hoc location for this. Use directive
inheritance instead.

> Background: I would like to have a LUA-script which handles every
> request and filters certain Headers, Parameters, etc.

Hopefully my solution given above works for you :)


More information about the nginx mailing list