zoukankan      html  css  js  c++  java
  • nginx记录日志时记录服务器响应的内容

    目前的 nginx 是不支持输出 response 报文体的 使用body_filter_by_lua来分配请求报文体给一个nginx变量。下面是一个示例

    worker_processes 1;
    error_log logs/error.log;
    events {
     worker_connections 1024;
    }
    http {
     log_format log_req_resp '$remote_addr - $remote_user [$time_local] '
     '"$request"$status $body_bytes_sent '
     '"$http_referer""$http_user_agent"$request_time req_body:"$request_body"resp_body:"$resp_body"';
    
     server {
     listen 8082;
     access_log logs/access.log log_req_resp;
    
     lua_need_request_body on;
    
     set $resp_body"";
     body_filter_by_lua '
     local resp_body = string.sub(ngx.arg[1], 1, 1000)
     ngx.ctx.buffered = (ngx.ctx.buffered or"") .. resp_body
     if ngx.arg[2] then
     ngx.var.resp_body = ngx.ctx.buffered
    end
    ';
    
     location / {
     echo"Hello World!";
    }
    }
    }

    原文地址:http://www.thinksaas.cn/group/topic/347828/

  • 相关阅读:
    c++类的知识点(1)
    并查集经典例题分析
    并查集
    bfs-迷宫
    出栈次序--数学归纳法--蓝桥
    九宫重排
    Tomcat详解
    寒假日记-第三天
    寒假日记-第二天(MySQL语句)
    Java学期总结
  • 原文地址:https://www.cnblogs.com/tm2015/p/4795535.html
Copyright © 2011-2022 走看看