Enable debugging and check the logs, or add Lua and dump variables to see what value is doing what (this is how I debug a flow). Posted at Nginx Forum: http://forum.nginx.org/read.php?2,251908,251923#msg-251923