首页 > 数据库技术 > 详细

nginx的access-log中添加cookie

时间:2016-03-15 00:52:05      阅读:298      评论:0      收藏:0      [点我收藏+]

因为业务需要,在访问页面中会添加一个cookie,方便业务的分析。

网上搜索“nginx 访问日志中添加cookie”出现很多访问,不过大家把内容全放在一起,甚至有一些访问中在server模块中出现log_format,因此把一些理解整理了一下。


http {

    include       mime.types;

    default_type  application/octet-stream;

    

    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘

                      ‘$status $body_bytes_sent "$http_referer" ‘

                      ‘"$http_user_agent" "$http_x_forwarded_for" $query_cookie‘;

    server {

        set $query_cookie "-";#设置默认值

        if ( $http_cookie ~* "uuid=(\S+)(;.*|$)"){

            set $query_cookie $1;

        }

        access_log  logs/api-access.log  main;

        listen       80;

        server_name  www.peter.com;

        root   D:/git/workspace/www.peter.com/;

        location / {

            index  index.php index.html index.htm;

        }

        location ~ \.php$ {

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

    }

}


uuid即为你要关注的cookie名,如果用户在浏览网站时,如果cookie中包含uuid,则会在access日志中包含uuid的值。

本文出自 “peter的未来” 博客,请务必保留此出处http://peterxu.blog.51cto.com/1391852/1750961

nginx的access-log中添加cookie

原文:http://peterxu.blog.51cto.com/1391852/1750961

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!