nginx 日志记录 cookie信息

php代码中cookie设置:

setcookie('uid_ssn' , $_SESSION['ssn'] , time() + 3600*24);

nginx配置:

http配置块中添加:
es_access是设定的日志记录格式参数
最后的request_uid就是日志中记录的cookie中的uid_ssn参数

log_format  es_access   '{'
		                  '"status":$status,'
		                  '"request_method":"$request_method",'
		                  '"request_uri":"$request_uri",'
		                  '"scheme":"$scheme",'
		                  '"server_addr":"$server_addr",'
		                  '"server_name":"$server_name",'
		                  '"time_iso8601":"$time_iso8601",'
		                  '"uri":"$uri",'
		                  '"remote_addr":"$remote_addr",'
		                  '"time_local":"$time_local",'
		                  '"body_bytes_sent":$body_bytes_sent,'
		                  '"http_referer":"$http_referer",'
		                  '"http_user_agent":"$http_user_agent",'
		                  '"http_x_forwarded_for":"$http_x_forwarded_for",'
		                  '"request_time":$request_time,'
		                  '"http_host":"$http_host",'
		                  '"request_uid":"$request_uid"'
		              '}';

server配置块中添加:
http_cookie即为获取的所有cookie信息
这里正则匹配下单独设置变量为$request_uid

access_log 为日志记录配置

if ($http_cookie ~* "uid_ssn=([A-Za-z0-9_]*)"){
   set $request_uid $1;
}
access_log  logs/es/main.log  es_access;

你可能感兴趣的:(Nginx)