美文网首页
[LNMP]Nignx access_log按天生成

[LNMP]Nignx access_log按天生成

作者: Cesium中文网 | 来源:发表于2019-04-11 14:34 被阅读0次

原文链接: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

相关文章

网友评论

      本文标题:[LNMP]Nignx access_log按天生成

      本文链接:https://www.haomeiwen.com/subject/oyptwqtx.html