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

╰+攻爆jí腚メ 2022-11-03 04:14 278阅读 0赞

安装 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

发表评论

表情:
评论列表 (有 0 条评论,278人围观)

还没有评论,来说两句吧...

相关阅读

    相关 ngx_http_discard_request_body

    http框架丢弃http请求包体和上一篇文章http框架接收包体, 都是由http框架提供的两个方法,供http各个模块调用,从而决定对包体做什么处理。是选择丢弃还是接收,都是