nginx 的日志记录 response 的报文头
2016-07-12 15:24
573 查看
场景
参考https://segmentfault.com/a/1190000000606867可以获取response的报文体,由于业务测试有获取响应头的需求,这里是通过header_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" resp_header:"$resp_header"'; server { listen 8082; access_log logs/access.log log_req_resp; set $resp_header ""; header_filter_by_lua ' local h = ngx.resp.get_headers() for k, v in pairs(h) do ngx.var.resp_header=ngx.var.resp_header..k..": "..v end '; 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!"; } } }
相关文章推荐
- Nginx搭建集群服务器过程详解
- nginx配置
- centos6.7上使用nginx实现负载均衡
- Nginx负载均衡配置实例详解
- nginx常见问题
- Nginx实现简易泛域名CDN节点
- Nginx泛解析的匹配域名绑定到子目录配置
- 多个PHP版本环境搭建(nginx,php)
- centos7重启apache、nginx、mysql、php-fpm命令
- nginx 的启动脚本
- Nginx做负载均衡无法加载css,js
- Nginx - Windows下Nginx初入门
- rtmp与hls流媒体服务器搭建:ubuntu下Nginx搭建初探与rtmp-module的添加
- linuex上搭建nginx步骤
- OpenResty(Nginx)+Lua+GraphicsMagick实现缩略图功能
- Nginx
- Ngnix+resin+SVN环境搭建
- nginx内置缓存Proxy_cache
- nginx.conf 配置文件说明
- CentOS 6.5 安装nginx及负载均衡配置