4 and then 5 is normal nginx behavior, your going to need something between 3 and 4, running a nginx debug build with full debugging on should show you the logging you need, locate this debug log code in the sources and build a normal version with only this debug line enabled.
A Lua solution is better asked here https://groups.google.com/forum/#!forum/openresty-en
just be clear (like your last post) what you want to happen, maybe someone there can give a hint.
A Lua solution is better asked here https://groups.google.com/forum/#!forum/openresty-en
just be clear (like your last post) what you want to happen, maybe someone there can give a hint.