nginx-test.conf
location /lua {
default_type 'text/plain';
content_by_lua '
local currtime = ngx.localtime()
local file = io.open("/tmp/nginx_lua.log", "a");
file:write(currtime, "\\t", ngx.var.uri, "\\n");
file:write("\\t", ngx.var.args, "\\n");
file:close();
ngx.print(currtime, "\\n");
ngx.print(ngx.var.uri,"\\n");
ngx.print(ngx.var.args,"\\n");
--ngx.print(ngx.var.request_body, "\\n");
';
}
/tmp/nginx_lua.log:
2013-07-29 04:19:07 /lua
a=1&b=c&d
Web:
2013-07-29 04:19:07
/lua
a=1&b=c&d
如此一來,當 request 進來時,可以查看 /tmp/nginx_lua.log 看看到底走了幾個 requests,留意項目:
- 在 content_by_lua 中,要印出 newline 必須用 ngx.print( "\\n" ) ,但如果是在 access_by_lua_file 中,只需 ngx.print( "\n" ) 即可。
- 註解是用 "--" 而非用 "#" 或 "//" 開頭
沒有留言:
張貼留言