码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx 日志中记录cookie

时间:2017-08-21 16:31:09      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:nginx

因开发要求,在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 Host $host;
        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 日志中记录cookie

标签:nginx

原文地址:http://536410.blog.51cto.com/526410/1958053

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!