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
配置錯誤日志


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM