首页 » Web开发 » 正文

[LNMP]Nignx access_log按天生成

之前一个服务,使用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;
	}
}

本文共 1 个回复

发表评论

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax