4-Nginx 日誌管理


1、Nginx日誌配置 分類ios

  access_log 訪問日誌配置web

  log_format 定義日誌格式算法

  open_log_file_cache 設置日誌緩存瀏覽器

  log_not_found 記錄不存在 日誌配置緩存

  log_subrequest 記錄子請求的日誌配置服務器

  rewrite_log Rewrite 日誌負載均衡

  error_log 錯誤日誌ide

2、日誌配置spa

  一、access_log 配置debug

  語法:access_log path [format [buffer=size [flush=time]]];

               access_log  path  gzip[=level][buffer=size][flush=time];

               access_log  syslog:server=address[parameter=value][format];

        access_log  off:

  默認值: access logs/access.log  main;

  可配置字段: http、server、location、 if in location、limit_execpt

 Gzip 壓縮等級

  Buffer 設置內存緩存區大小

  Flush 保存在緩存區中的最長時間

  不記錄日誌:access_log off;

  使用默認combined 格式記錄日誌: access_log logs/access.log main;

 二、log_format配置

  語法:log_format name string …;

 默認值: log_format main "…";

 配置段: http

 ----------------------

 name:表示日誌格式的名稱 

 string:表示定義的格式

  log_format 有一個默認的無需配置的main日誌格式:

 wKioL1cODXDw2EDWAAAT6o8mNLY570.png


  注意:若是Nginx當作負載均衡器、反向代理使用後,web服務器沒法直接獲取到客戶端的真是的IP地址了。

      $remote_addr  獲取反向代理的IP地址。 反向代理服務器的轉發請求的http頭信息中,能夠增長X-Forwarded-For 信息。用來計入客戶端IP地址和客戶端請求的服務器地址

 wKioL1cODYzRAUA2AAAR_-rIkas314.png

 變量參數詳解:

    $remote_addr,$http_x_forwarded_for   記錄客戶端IP地址

    $remot_user 記錄客戶端用戶名稱

    $request   記錄請求的URL和HTTP協議

    $status 記錄請求狀態碼

    $body_bytes_sent 發送客戶端的字節數,不包括響應頭的大小,

    $bytes_sent 發送給客戶端的總字節數

    $connection 鏈接的序列號

    $connection_request 當前經過一個連接得到的請求數量

    $msec 日誌寫入時間。單位爲秒,精度是毫秒

    $pipe 若是請求是經過HTTP流水線(pipelined)發送,pipe值爲 「p」,不然爲「.」。

    $http_referer 記錄從哪一個頁面鏈接訪問過來的

     $http_user_agent 記錄客戶端瀏覽器相關信息

     $request_length 請求的長度(包括請求行,請求頭,和請求正文)

     $request_time 請求處理時間,單位爲秒,精度爲毫秒

     $time_ios8601 ISO8601標準格式下的本地時間

     $time_local 通用日誌格式下的本地時間

三、open_log_file_cache配置

 語法:open_log_file_cache max=N [inactive=time] [min_user=N] [valid=time];

               open_log_file_cache off;

  默認配置:open_log_file_cache off;

 可配置字段: http、server、location

  

 對於每一條日誌記錄,都將是先打開文件,再寫入日誌,而後關閉。可使用open_log_file_cache來設置日誌文件緩存(默認是OFF),格式以下:

  max:設置緩存中的最大文件描述符數量,若是緩存被佔滿,採用LRU算法將描述關閉

  inactive:設置存活時間,默認是10秒

  min_uses:設置在inactive 時間段內,日誌文件最少使用多少次後,該日誌文件描述符記入緩  存中,默認是1次。

四、log_not_found 配置

語法:log_not_found on|off;

默認值:log_not_found on;

可配置字段:http、server、location

做用:是否正在error_log中記錄不存在的錯誤。默認是。

五、log_subrequest配置

語法:log_subrequest on|off;

默認值:log_subrequest off;

可配置字段:http、server、location

是否在access_log 中記錄子請求的訪問日誌。默認不記錄。

六、rewrite_log指令

由ngx_http_rewrite_module 模塊提供。用來記錄重寫日誌的。在調試的時候建議打開。

語法:rewrite_log on|off;

默認值:rewrite_log off;

可配置字段:http、server、location、if

啓用時在error_log中記錄notice級別的重寫日誌。

七、error_log指令

語法:error_log file | stderr | syslog:server=address[parameter=value][debug|info|notic|warn|error|crit|alert|emerg];

默認值:error_log logs/error.log error;

可配置字段:main、http、server、location

配置錯誤日誌

相關文章
相關標籤/搜索