[gophper]nginx日志配置
谷歌统计因为某些原因服务不是很友好。现在统计分析主要依赖百度统计。。。 本着学习的态度,对现有日志进行分析统计。 数据分析可以发现网站自身问题同时可以了解不同地区的访问意向等。
构想
1.固定日志格式(nginx日志配置)
'$remote_addr|$http_x_forwarded_for|$time_local|$http_host|$request_uri|$status|$bytes_sent|$request_time|$http_referer|$http_user_agent'
2.分析来源
根据$remote_addr, $http_x_forwarded_for(客户端ip),按照时、天、月、年,进行来源地域统计,来源ip统计, 独立ip统计,运营商统计
3.分析请求URL
根据 $http_host,$request_uri(请求url),进行目标url统计,域名统计
4.分析user_agent
根据 $http_user_agent 进行浏览器信息统计,系统环境统计,网络设备统计
5.分析响应状态
根据$status进行响应状态统计
6.分析网络状态统计和响应数据大小
根据$bytes_sent和$request_time进行网络状态统计,响应数据大小统计
7.分析refer统计
根据 $http_referer进行refer统计
nginx配置说明
log_format 日志说明
$remote_addr, $http_x_forwarded_for 记录客户端IP地址
$remote_user 记录客户端用户名称
$time_local 记录本地时间
$http_host 请求域名
$request 请求的url与http协议
$request_uri 请求url
$request_length 请求的长度(包括请求行,请求头和请求正文)。
$request_time 请求处理时间,单位为秒,精度毫秒;从读入客户端的第一个字节开始,直到把最后一个字符发送给客户
$status 请求状态,成功是200
$body_bytes_sent 发送给客户端的字节数,不包括响应头的大小
$bytes_sent 发送给客户端的总字节数
$http_referer 记录从哪个网站访问过来
$http_user_agent 浏览器相关信息
线上配置备份
- nginx.conf
log_format access '$remote_addr|$http_x_forwarded_for|$time_local|$http_host'
'|$request_uri|$status|$bytes_sent|$request_time|$http_referer'
'|$http_user_agent';
- vhost/www.gophper.com.conf
server {
listen 80;
server_name gophper.com www.gophper.com;
root /home/www-root/www.gophper.com/dest;
access_log /opt/logs/www.gophper.com/access.log access;
index index.php index.html index.htm;
error_page 404 /archive.html;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /share {
autoindex on;
charset utf-8,gbk;
autoindex_exact_size off;
autoindex_localtime on;
}
}
- nginx_log_split.sh
#!/bin/sh
destdate=`/bin/date -d '-15 minutes' +%Y%m`
destday=`/bin/date -d '-15 minutes' +%d`
for i in www.gophper.com log.gophper.com
do
destdir="/opt/logs/${i}/${destdate}"
srclog="/opt/logs/${i}/access.log"
destlog="/opt/logs/${i}/${destdate}/access${destday}.log"
if [ ! -d ${destdir} ]; then
mkdir -p ${destdir}
fi
mv ${srclog} ${destlog}
done
/opt/nginx/sbin/nginx -s reload
- /etc/crontab
0 0 * * * root /opt/bin/nginx_log_split.sh