Nginx笔记总结九:Nginx日志配置

ngx_http_log_module用来定义请求日志格式
1. access_log指令
  语法:   access_log path [format [buffer=size [flush=time]]]
      access_log path format gzi=[level] [buffer=size] [flush=time]
      access_log syslog:server=address[,paramter=value] [format];
      access_log off;
      默认值:access_log logs/access.log combined;
      配置段:http,server,location,if in location, limit_except
      gzip压缩等级
      buffer设置内存缓冲区大小
      flush保存在缓冲区中的最长时间
      不记录日志:access_log off #好像没作用
2. log_format指令
    语法:log_format name string ......
    配置段:http
    name 表示格式名称,string表示定义的格式
    log_format combined '$remote_addr - $remote_user [$time_local]'
        '"$request" $status $body_tytes_sent'
        ' $http_referer "$http_user_agent"'

    log_format proxy '$http_x_forwarded_for - $remote_user [$time_local]'
          '"$request" $status $body_bytes_sent'
          ' "$http_referer " " $http_user_agent"';
3. 日志格式允许包含的变量:
  $remote_addr, $http_x_forwarded_for 记录客户端IP地址
  $remote_user         记录客户端名称
  $request             记录请求的URL和HTTP协议
  $status           记录请求状态
  $body_bytes_sent       发送给客户端的字节数,不包括响应头的大小
  $bytes_sent       发送给客户端的总字节数
  $connection        链接的序列号
  $connection_requests   当前通过一个链接获得的请求数量
  $msec           日志写入时间,单位为秒,精确是毫秒
  $pipe           如果请求时通过http流水线发送,pipe值为p,否则为.
  $http_referer                记录从那个页面链接访问过来的
  $http_user_agent        记录客户端浏览器相关信息
  $request_length          请求的长度
  $request_time             请求处理时间,单位为秒,精确度毫秒
  $time_iso8601             标准格式下的本地时间
  $time_local                  通用日志格式下的本地时间
4. open_log_file_cache指令
  语法:open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time]
  默认值:open_log_file_cache off;
  配置段:http,server,location
      max:最大文件描述符数量
      inactive:存货时间,默认10s
      min_uses:设置在inactive时间段中,日志文件最少使用多少次,该日志文件描述符记入缓存中,默认1次
      valid:设置检查频率,默认60s
      off:禁用
      open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;

5. log_not_found指令
语法:log_not_found on | off
默认值:log_not_found on;
匹配段:http,server,location
是否在error_log中记录不存在的错误,默认on
6. log_subequest指令
语法:log_subrequest on | off;
默认值:log_subrequest off;
配置段:http,server,location
是否在access_log中记录子请求的访问日志,默认off
7. rewrite_log指令
由ngx_http_rewrite_module模块提供,用来记录重写日志
语法:rewrite_log on | off;
默认值 rewrite_log off;
配置段:http,server,location,if
启用时将error log中记录notice级别的重写日志
8. error_log指令
语法:error_log | stderr | syslog:server=address[,parameter=value [debug | info| notice| warn | error | crit | alert | emerg]]
默认值:error_log logs/error.log error;
配置段:main,http,server,location
配置错误日志

posted @ 2017-02-14 10:18  喝杯茶  阅读(2637)  评论(0编辑  收藏  举报