nginx 访问日志 access.log 添加设置cookie记录

http://ju.outofmemory.cn/entry/105503

需求,把cookie记录到访问日志里,供数据挖掘部门统计用户行为。 nginx 配置文件添加如下,这是虚拟主机的配置

server
{# 在server块添加以下代码# 设置默认值set $uid "-";# 存在值则赋值if( $http_cookie ~*"at_uvid=(\S+)(;.*|$)"){set $uid $1;}# 最后一段数据是该cookie值
	log_format  uid_log  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for" "$uid"';
				  
	access_log  /var/log/nginx/gretheer.com.log  uid_log;#到此结束}

猜你喜欢

转载自kavy.iteye.com/blog/2256467