使用nginx lua模块将post的request body记录到access log中但是当数据包过大的时候会出现无法记录到log中的情况,于是就根据配置项’lua_need_request_body’去找nginx lua代码,然后由于其良好的封装性并没有很快的定位到代码位置!!!,之后看文档赫然看到client_body_buffer_size、client_max_body_size,两个值需要相同,不然当请求的数据格式大于前者并且小于后者的时候就会将数据暂存到硬盘上,这样最终会导致request_body是空值!!!终于找到了原因,这么一想这个配置还会严重影响到nginx的性能啊!!
lua_need_request_body
syntax: _lua_need_request_body <on|off>_
default: off
context: http, server, location, location if
phase: depends on usage
Determines whether to force the request body data to be read before running rewrite/access/access_by_lua* or not. The Nginx core does not read the client request body by default and if request body data is required, then this directive should be turned on
or the ngx.req.read_body function should be called within the Lua code.
To read the request body data within the $request_body variable, client_body_buffer_size must have the same value as client_max_body_size. Because when the content length exceeds client_body_buffer_size but less than client_max_body_size, Nginx will buffer the data into a temporary file on the disk, which will lead to empty value in the $request_body variable.
If the current location includes rewrite_by_lua* directives, then the request body will be read just before the rewrite_by_lua* code is run (and also at the rewrite
phase). Similarly, if only content_by_lua is specified, the request body will not be read until the content handler’s Lua code is about to run (i.e., the request body will be read during the content phase).
It is recommended however, to use the ngx.req.read_body and ngx.req.discard_body functions for finer control over the request body reading process instead.
This also applies to access_by_lua*.
转载请注明来源链接 http://just4fun.im/2017/01/22/nignx-rquest/ 尊重知识,谢谢:)