您的位置:首页 > 运维架构 > Nginx

Nginx 日志中记录cookie

2017-08-21 15:41 483 查看
因开发要求,在Nginx日志中需要记录Cookie信息,以便开发查询系统发生了什么,我的日志是以json格式显示,需要在nginx.conf文件中添加如下信息:
1,#vim nginx.conf

http {
include mime.types;
default_type application/octet-stream;
log_format logstash_json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"url":"$uri",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"agent":"$http_user_agent",'
'"@req_body":"$request_body",'
'"$http_cookie":"$http_cookie",' 添加这行
'"status":"$status"}';

location ~* ^/test/.*$ {
proxy_hide_header Set-Cookie; 添加这行
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.9.54.1:797; 2,再查看Nginx日志,就可以显示Cookie信息了


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Nginx