nginx日志
2013-09-14 14:53
621 查看
log_format
context: http,server
syntax: log_format name 'format string ...';
注:format string可以使用一般变量,也可以使用写入日志那些刻的变量(过程变量)
$body_bytes_sent $bytes_sent $connection $msec $pipe $request_length
$request_time $status $time_iso8601 $time_local
其它一些变量
$sent_http_content_range upstream_http_...
access_log
context: http,server,location
syntax: acces_log path [format [buffer=size [flush=time]]] | off
注:
如果不指定format默认使用combined格式;
buffer
默认关闭,如果path中包含变量,则不能使用buffer参数;
使用buffer,必须指定日志format;
使用flush必须使用buffer,作用:在缓存没有填满的情况下,超过flush指定的时间将强制写入到日志文件。
如果设置为off,将关闭继承的access_log参数;
path
0.7.4版本以上,path可以包含变量,但是这样的日志有一定的限制,如下:
worker用户必须有新建文件的权限;
不能使用缓存
open_log_file_cache
功能:缓存频繁使用的日志文件描述符
syntax: open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];
open_log_file_cache off;
default: open_log_file_cache off;
context: http, server, location
经过测试:访问约5到6次会产生1k的日志文件,如果buffer设置32k,也就是说要访问32*6=192/次才能填满缓存,这个根据实际需要调整配合flush参数使用。
实际生产中,如果需要记录日志,可以使用以下格式:
注: 使用以上配置,各站点日志的目录不需要有worker进程用户的创建文件的权限,但是如果使用logs/$server_name.access.log这种配置,则需要创建文件权限。但是使用这种配置不能使用buffer,降低服务器性能。
logs/$server_name.access.log使用该配置时,如果server_name配置了多个参数,取第一个。
==================================================================
日志切割脚本:
详见:/article/4287454.html
本文出自 “notepad” 博客,请务必保留此出处http://sndapk.blog.51cto.com/5385144/1297051
context: http,server
syntax: log_format name 'format string ...';
注:format string可以使用一般变量,也可以使用写入日志那些刻的变量(过程变量)
$body_bytes_sent $bytes_sent $connection $msec $pipe $request_length
$request_time $status $time_iso8601 $time_local
其它一些变量
$sent_http_content_range upstream_http_...
access_log
context: http,server,location
syntax: acces_log path [format [buffer=size [flush=time]]] | off
注:
如果不指定format默认使用combined格式;
buffer
默认关闭,如果path中包含变量,则不能使用buffer参数;
使用buffer,必须指定日志format;
使用flush必须使用buffer,作用:在缓存没有填满的情况下,超过flush指定的时间将强制写入到日志文件。
如果设置为off,将关闭继承的access_log参数;
path
0.7.4版本以上,path可以包含变量,但是这样的日志有一定的限制,如下:
worker用户必须有新建文件的权限;
不能使用缓存
open_log_file_cache
功能:缓存频繁使用的日志文件描述符
syntax: open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];
open_log_file_cache off;
default: open_log_file_cache off;
context: http, server, location
maxsets the maximum number of descriptors in a cache; if the cache becomes full the least recently used (LRU) descriptors are closed
inactivesets the time after which the cached descriptor is closed if there were no access during this time; by default, 10 seconds
min_usessets the minimum number of file uses during the time defined by the
inactiveparameter to let the descriptor stay open in a cache; by default, 1
validsets the time after which it should be checked that the file still exists with the same name; by default, 60 seconds
offdisables cachingUsage example:
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;总结:
经过测试:访问约5到6次会产生1k的日志文件,如果buffer设置32k,也就是说要访问32*6=192/次才能填满缓存,这个根据实际需要调整配合flush参数使用。
实际生产中,如果需要记录日志,可以使用以下格式:
http { open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2; server { server_name test.cn; access_log /var/log/nginx/test.cn/access.log combined buffer=32k flush=1m; } }
注: 使用以上配置,各站点日志的目录不需要有worker进程用户的创建文件的权限,但是如果使用logs/$server_name.access.log这种配置,则需要创建文件权限。但是使用这种配置不能使用buffer,降低服务器性能。
logs/$server_name.access.log使用该配置时,如果server_name配置了多个参数,取第一个。
==================================================================
日志切割脚本:
详见:/article/4287454.html
本文出自 “notepad” 博客,请务必保留此出处http://sndapk.blog.51cto.com/5385144/1297051
相关文章推荐
- python实现分析apache和nginx日志文件并输出访客ip列表的方法
- nginx日志解析
- 从nginx访问日志中的400错误说起
- ELK实战之收集Nginx的json格式日志
- nginx错误日志入库小程序
- Nginx 模块开发之日志模块---实时记录http请求信息写入flume
- nginx运维(3)nginx虚拟主机,日志管理与location
- nginx日志问题解决方法记录
- Nginx实现大日志文件切割
- 怎样配置让apache访问日志记录真实客户端IP,而不是nginx代理服务器IP
- Logstash+Redis+Elasticsearch+Kibana 快速搭建Nginx日志查询系统
- Nginx 日志配置详情解析
- 使用logrotate做的nginx日志切割
- Nginx运行日志自动切割
- kibana上nginx访问日志分析
- ELK(二)nginx日志分析
- Nginx 改变错误日志打印级别
- Nginx 日志分析及性能排查
- Nginx自定义访问日志的配置方式
- nginx关闭日志