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

nginx的access-log中添加cookie

2016-03-14 16:50 543 查看
因为业务需要,在访问页面中会添加一个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的值。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cookie nginx