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的值。
网上搜索“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的值。
相关文章推荐
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- Nginx 学习笔记(一)
- 网站502与504错误分析
- 用zabbix监控nginx_status状态
- cookie的secure属性详解
- 浏览器 cookie 限制
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 把Lua编译进nginx步骤方法
- android读写cookie的方法示例
- web 应用中常用的各种 cache详解
- 浅谈COOKIE和SESSION区别