原文链接:http://blog.coinidea.com/web%E5%BC%80%E5%8F%91-1420.html
之前一个服务,使用nginx做了转发,因为访问量比较大,想在nginx这一层做一个简单的access统计,发现nginx默认的access_log是统计在一个文件中的,这样非常不方便,所以查了一下,很多人说用shell脚本来解决这个问题,终于,找到了比较好的解决方式,Nginx支持配置:
server {
listen 8082;
server_name your ip;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})"){
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
set $minutes $5;
set $seconds $6;
}
access_log logs/8082_$year-$month-$day.log;
error_log logs/8082.error;
#将所有请求转发
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8082;
}
}
原文链接:http://blog.coinidea.com/web%E5%BC%80%E5%8F%91-1420.html
网友评论