http://www.huomo.cn/sysapp/article-63a3.html
群众的力量是巨大的,群众的智慧是无穷的。其实这次的需求就让我体会到这句话的意义。
现有一需求,需要把我们手机网站的cookie信息记录到access.log里,数据挖掘部门需要根据这个来统计用户行为。其实我还真没有这样记录过日志,后来百度了一下,发现Nginx确实很强大。
具体实现看配置:
server { listen 80; server_name 192.168.1.101; #setting cookie log #if ( $http_cookie ~* "wap_auth=(.+)(?:;|$)" )如果要对应cookie名称,可以这么做 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; }
其实从这个小小的需求里边得到的经验远远不止于此,这个就是为什么我的标题不叫nginx日志记录cookie的原因,请大家自己体会!
转载于:https://blog.51cto.com/815632410/1569834