获取响应内容

log_format cntr escape=json '{"time":"$time_local",'
                        '"@source":"$server_addr",'
                        '"hostname":"$hostname",'
                        '"xforward":"$http_x_forwarded_for",'
                        '"remoteaddr":"$remote_addr",'
                        '"method":"$request_method",'
                        '"scheme":"$scheme",'
                        '"domain":"$server_name",'
                        '"referer":"$http_referer",'
                        '"requrl":"$request_uri",'
                        '"args":"$args",'
                        '"requestbody":"$request_body",'
                        '"contentlength":"$content_length",'
                        '"bodybytessend":$body_bytes_sent,'
                        '"status":$status,'
                        '"requesttime":$request_time,'
                        '"upstreamtime":"$upstream_response_time",'
                        '"upstreamaddr":"$upstream_addr",'
                        '"respbody":"$resp_body",'
                        '"respdown":"$resp_ctrl_down",'
                        '"useragent":"$http_user_agent"'
                        '}';
location /abc {
        #access_log off;
        access_log /data/logs/nginx/abc/access.log cntr buffer=32k flush=5s;
        error_log /data/logs/nginx/abc/error.log info;

        set $resp_ctrl_down -1;
        set $resp_body "";
        # only elk collection machine, can add the below lua code.
        body_filter_by_lua_block {
            local chunk, eof = ngx.arg[1], ngx.arg[2]
            ngx.var.resp_body=ngx.var.resp_body..chunk
            if eof then
               if string.find(ngx.var.resp_body,'"count":true') then
                  ngx.var.resp_ctrl_down = 1
               else
                  ngx.var.resp_ctrl_down = 0
               end
            end
        }

        proxy_pass http://abc/flow;
    }