post_action for specific requests only

ahurkala nginx-forum at nginx.us
Thu Feb 20 20:32:28 UTC 2014


Hi, i'm using post_action for remote logging. Logging all requests works
great and efficient (4k req/s) but when I try to log only certain requests
ngix becomes unstable (some connections hang and some weird errors occur).
I've tried several ways to log specific requests only, but none of them
works stable:
1) first way (if directive)
post_action @afterdownload;
location @afterdownload {
        if ($foo) {
                proxy_pass blah
        }
}
2) second way (lua)
post_action @afterdownload;
location @afterdownload {
access_by_lua '
        if ngx.var.blah then
                ngx.location.capture(....)
        end
        ngx.exit(ngx.HTTP_OK)
';
}
3) third way (lua)
post_action /afterdownload;
location /afterdownload {
access_by_lua '
        if ngx.var.blah then
                ngx.location.capture(....)
        end
        ngx.exit(ngx.HTTP_OK)
';
}

First way involves evil 'if' so I assume it might not work smoothly, but
what's wrong with the second or 3rd approach? It seems that if you remove
ngx.exit() from the 3rd method it kinda works, but this way you get lots of
404 errors saying that /afterdownload is not found.
I've read here
(http://mailman.nginx.org/pipermail/nginx/2012-November/036199.html) that
post_action is executed in a context of main requests which explains a bit,
but maybe there is a way for logging only specific requests (like setting
post_action from lua maybe)?

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,247815,247815#msg-247815



More information about the nginx mailing list