Nginx访问日志格式设置

自定义一下nginx的访问日志格式,可以方便工作中的对日志的分析。主要要使用到几个指令,分别是log_format和access_log、error_log   Example:
#WebLog
log_format weblog	'$remote_addr - $remote_user [$time_local] "$request" '
			'$status $body_bytes_sent "$http_referer" '
			'"$http_user_agent" $http_x_forwarded_for';
 
access_log  /data/logs/domain_access.log  access;
error_log  /data/logs/domain_error.log error;
log_format指令:
-------------------------------------
语法	log_format name string ...
-------------------------------------
默认值	combined "..."
-------------------------------------
使用字段	http
-------------------------------------
参数说明:
    []$remote_addr 和 $http_x_forwarded_for:记录客户端的ip地址。[/][]$remote_user:记录客户端用户名称。[/][]$time_local:记录访问时间与时区。[/][]$request:记录请求的URL与HTTP协议。[/][]$status:记录请求状态;成功是200。[/][]$body_bytes_sent:记录发送给客户端文件主体内容大小。[/][]$http_referer:记录从那个页面链接访问过来的。[/][]$http_user_agent:记录客户端浏览器的相关信息。[/]
access_log指令:
--------------------------------------------------------
语法	access_log path [ format [ buffer = size ]]
        access_log off
--------------------------------------------------------
默认值	logs/access.log combined
--------------------------------------------------------
使用字段	http
            server
            location
            if in location
            limit_except
---------------------------------------------------------
记录的日志格式如下:
66.249.73.68 - - [17/Dec/2015:17:03:52 +0800] "GET /2011/11/1659.html HTTP/1.1" 200 9028 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
115.28.133.87 - - [17/Dec/2012:17:03:53 +0800] "GET /2012/03/8907.html HTTP/1.1" 200 8044 "http://www.baidu.com/s?wd=web%20equation&ie=utf-8" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)"
115.28.133.87 - - [17/Dec/2012:17:03:54 +0800] "GET /favicon.ico HTTP/1.1" 200 1150 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; 360SE)"

0 个评论

要回复文章请先登录注册