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
还没有评论,来说两句吧...