I think I found it now:<div><br></div><div><div>location / {</div><div> lua_need_request_body on;</div><div> </div><div> client_max_body_size 100k;</div><div> client_body_buffer_size 100k;</div>
<div> </div><div> access_by_lua '</div><div> -- check the client IP address is in our black list</div><div> if ngx.var.remote_addr == "132.5.72.3" then</div><div> ngx.exit(ngx.HTTP_FORBIDDEN)</div>
<div> end</div><div> </div><div> -- check if the request body contains bad words</div><div> if ngx.var.request_body and</div><div> string.match(ngx.var.request_body, "fsck")</div>
<div> then</div><div> return ngx.redirect("/terms_of_use.html")</div><div> end</div><div> </div><div> -- tests passed</div><div> ';</div>
<div> </div><div><br></div><div class="gmail_quote">On Sun, Jul 8, 2012 at 4:28 PM, Mike Gagnon <span dir="ltr"><<a href="mailto:mikegagnon@gmail.com" target="_blank">mikegagnon@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote"><div class="im">On Sat, Jul 7, 2012 at 8:19 PM, agentzh <span dir="ltr"><<a href="mailto:agentzh@gmail.com" target="_blank">agentzh@gmail.com</a>></span> wrote:<br></div><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>> Is it possible to hack nginx such that the rewrite phase is delayed until<br>
> after the request_body is available? I am writing a module that analyzes<br>
> requests during the rewrite phase to determine where to route them. The goal<br>
> is to use online machine learning to detect suspicious requests and re-route<br>
> them to a quarantine. <a href="http://mikegagnon.com/2012/06/08/beer-garden/" target="_blank">http://mikegagnon.com/2012/06/08/beer-garden/</a><br>
><br>
<br>
</div>We're just using ngx_lua to do suspicious request filtering in rewrite<br>
and/or access phases. It's convenient (and also rather efficient) to<br>
use the various Lua APIs for Nginx provided by ngx_lua. See<br>
<br>
<a href="http://wiki.nginx.org/HttpLuaModule" target="_blank">http://wiki.nginx.org/HttpLuaModule</a><br>
<br></blockquote><div><br></div></div><div>Oh, yeah I ment to ask, but forgot. I'm curious to learn more about your code to filter suspicious requests. I looked at <a href="http://wiki.nginx.org/HttpLuaModule" target="_blank">http://wiki.nginx.org/HttpLuaModule</a> but did not see anything specifically regarding filting suspicious requests.</div>
<div><br></div><div>Thanks again!</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Mike Gagnon</div></font></span></div>
</blockquote></div><br></div>