java request body内容_nginx 配置记录 request body 内容

安装 NGINX的 openresty

因为 openresty 功能更强大。直接下载使用更好

参考: http://openresty.org/cn/components.html

https://my.oschina.net/wForget/blog/3224595

https://moonbingbing.gitbooks.io/openresty-best-practices/content/openresty/get_req_body.html

https://www.cnblogs.com/winss/p/13569452.html

配置 内容 写入log 文件

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

lua_package_path "$prefix/?.luac;$prefix/?.lua;;";

# 日志文件格式 user_defined.log 数据会写到这个文件中

log_format user_log_format escape=json '{"time": "$msec", "ip": "$remote_addr","referer":"$http_referer" ,"ua": "$http_user_agent", "data": "$p_body"}';

server {

listen 8080;

set $p_body "";

# 用于按天生成日志

if ($time_iso8601 ~ "(\d{4}-\d{2}-\d{2})") {

set $day $1;

}

location / {

root html;

index index.html index.htm;

}

location /test {

lua_need_request_body on;

content_by_lua '

local p_body = ngx.req.get_body_data() or ""

ngx.var.p_body = p_body

';

access_log D:/buildSoft/front/Openresty_For_Windows_1.13.5.1001_64Bit/x64/nginx/logs/log_body_$day.log user_log_format;

}

}

}

配置将 内容写入 DB

使用 lua-resty-mysql 即可。 参考: https://blog.csdn.net/cuichunchi/article/details/89672967

https://github.com/openresty/lua-resty-mysql

异步执行: https://moonbingbing.gitbooks.io/openresty-best-practices/content/ngx_lua/continue_after_eof.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值