事例(二)
现有一需求,需要把我们手机网站的cookie信息记录到access.log里,数据挖掘部门需要根据这个来统计用户行为。其实我还真没有这样记录过日志,后来百度了一下,发现Nginx确实很强大。
具体实现看配置:
server
{
listen 80;
server_name 192.168.1.101;
#setting cookie log
#if ( $http_cookie ~* "wap_auth=(. )(?:;|$)" )
if ( $http_cookie ~* "(.*)$")
{
set $wap_cookie $1;
}
index index.php index.htm index.html;
add_header Load-Balancing $server_addr;
root /server/www/apps/wap_v2;
rewrite ^/css/(.*)$ /media/css/$1 last;
location /logs {
alias /data/nginx/logs/;
}
location ~* .*\.(php|html)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location /nginx-status {
stub_status on;
allow 192.168.1.171;
deny all;
}
log_format wap_access '$remote_addr $host \
$server_addr [$time_local] "$request \
" ' '$status $body_bytes_sent \
"$http_referer" ' '"$http_user_agent\
" "$wap_cookie"';
access_log /data/nginx/logs/access_wap.log wap_access;
}
事例(三)
set $user_id "0"; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $user_id "$uuid" ';