Nginx日志记录Cookie 学习笔记
来源:互联网 发布:阿里云 cdn 备案 编辑:程序博客网 时间:2024/06/08 08:08
listen 80;
server_name www.aslibra.com;
set $aslibra_auth "";
if ( $http_cookie ~* "aslibra_auth=(.+)(?:;|$)" ){
set $aslibra_auth $1;
}
log_format main '$proxy_add_x_forwarded_for - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" $aslibra_auth ';
access_log /Data/log/nginx-access.log main;
location / {
root /Data/webapps/www.aslibra.com/;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
参考分割日志的脚本:
log_dir="/Data/log"
time=`date +%Y%m%d`
/bin/mv ${log_dir}/nginx-access.log ${log_dir}/nginx-access.$time.log
kill -USR1 `cat /var/run/nginx.pid`
事例(二)
现有一需求,需要把我们手机网站的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";#获取uuid
set $uuid "_";
if ( $http_cookie ~* "user_id=([0-9]*)" ){
set $user_id $1;
}
if ( $http_cookie ~* "_uuid=([A-Za-z0-9 ]*)" ){
set $uuid $1;
}
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" ';
- Nginx日志记录Cookie 学习笔记
- nginx日志切割和记录cookie
- Nginx和Apache配置日志格式记录Cookie
- nginx 学习笔记(5) nginx调试日志
- nginx日志记录切割
- nginx学习笔记5 nginx日志文件的配置
- Nginx 记录请求分发日志
- 自定义nginx日志记录格式
- Nginx 记录请求分发日志
- nginx日志中显示cookie信息
- Hadoop学习笔记之flume Nginx日志收集到HBase
- Nginx学习日志
- apache日志通过cookie记录独立访客
- nginx 实战学习记录
- nginx学习记录
- nginx学习记录
- 对nginx学习记录
- nginx学习记录
- keepdalived+lvs 负载均衡
- 如何查看Linux是32位还是64位,以及发行版本
- SiftGPU
- linux 32位和linux64位有什么区别
- 在linux下如何查看CPU是否支持64位的方法
- Nginx日志记录Cookie 学习笔记
- 计算机视觉方面的代码
- ss
- poj 3373
- 爱学习,爱编程,爱咖啡可乐 爱挑战,爱钻研,爱打游戏 爱晚起,也爱工作到深夜 我擅长技术,崇尚简单和懒惰 我神秘而孤僻,沉默而爱憎分明 Don't Panic! I'm a programmer
- nodejs简单应用五( 提高页面加载速度---304与压缩)
- 黑马程序员08-GUI自我提问
- 关于ppc的32位立即数加载问题
- 位置无关代码(PIC)在 Bootloader 中的应用