Nginx正确记录post日志的方法事实上可以很简单,这取决于把 access_log 放在哪个 location 里面。一,放到包含fastcgi_pass或proxy_pass的Location里面。如下:[php] view plaincopy location ~ \.php$ { root /data/webapps; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/webapps$fastcgi_script_name; access_log post_log /tmp/post.log } post_log 为 http 区域里面定义的日志格式,可以是这样:[php] view plaincopy log_format post_log '$remote_addr - $request_body'; $request_body 即为post的数据。 然后post数据到这个目录下的.php文件,就可以记录post日志了。二,放到任意Location里面。具体步骤如下:1,安装LuaJITwget http://luajit.org/download/LuaJIT-2.0.1.tar.gztar -zxvf LuaJIT-2.0.1.tar.gzmake PREFIX=/data/apps/luajit2.0.1make install PREFIX=/data/apps/luajit2.0.2,下载并解压以下两个个模块http://github.com/simpl/ngx_devel_kit/tagshttp://github.com/chaoslawful/lua-nginx-module/tags把解压后的2个目录分别移动到 /usr/local/src/ 目录下面(个人习惯而已)3,重新编译Nginxexport LUAJIT_LIB=/data/apps/luajit2.0.1/libexport LUAJIT_INC=/data/apps/luajit2.0.1/include/luajit-2.0./configure --prefix=/data/apps/nginx --add-module=/usr/local/src/ngx_devel_kit-0.2.19 --add-module=/usr/local/src/lua-nginx-module-0.9.2make -j2make install4,然后在需要记录post日志的Location里面加上如下语句:[php] view plaincopy lua_need_request_body on; content_by_lua 'local s = ngx.var.request_body'; log_format post_log '$remote_addr - $request_body'; 5,在启动Nginx的时候如果报错:error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory解决:ln -s /data/apps/luajit2.0.1/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2参考文档:http://www.cnblogs.com/meteorx/p/3188647.htmlhttp://wiki.nginx.org/HttpLuaModule#Synopsis