nginx日志中记录post数据

nginx记录post数据,需要安装lua-nginx-module模块

1、下载luajit: http://luajit.org/download.html

      make prefix=/usr/local/luajit

      make install prefix=/usr/local/luajit

2、下载ngx_devel_kit模块

      https://github.com/simpl/ngx_devel_kit/

解压到 /usr/local/src/ngx_devel_kit

3、下载lua-nginx-module模块

https://github.com/openresty/lua-nginx-module

解压到 /usr/local/src/lua_nginx_module

4、添加环境变量

exportLUAJIT_LIB=/usr/local/luajit/lib

exportLUAJIT_INC=/usr/local/luajit/include/luajit-2.0

5、nginx 编译

--user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-openssl=/root/lnmp1.4-full/src/openssl-1.0.2l --add-module=/usr/local/src/ngx_devel_kit --add-module=/usr/local/src/lua-nginx-module

6、添加共享库

echo "/usr/local/luajit/lib" >> /etc/ld.so.conf

ldconfig

7、配置nginx

 在location /{}中添加

lua_need_request_body on;
        content_by_lua_block {
         ngx.req.read_body()
         local args, err = ngx.req.get_post_args(),ngstr,
         if not args then
             ngx.say("failed to get post args: ", err)
             return
         end
         for key, val in pairs(args) do
             if type(val) == "table" then
                 ngstr = '$ngstr - ngx.say(key, ": ", table.concat(val, ", "))'
             else
                 ngstr = '$ngstr - ngx.say(key, ": ", val)'
             end
             $request_body = ngstr
         end
        }

开启log access_log  /home/wwwlogs/XXX.log main;

http 中配置日志格式

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent $request_body "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值