nginx 日誌模塊

控制nginx如何記錄請求日誌

中文文檔 http://www.nginx.cn/doc/standard/httplog.html

官方文檔 http://nginx.org/en/docs/http/ngx_http_log_module.html

建議兩個文檔個都看看防止遺漏中文文檔不全

主要指令

  access_log
  log_format
  open_log_file_cache

注意使用日誌功能時當前用戶必須有寫入日誌的權限

Syntax: access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];
access_log off;
Default:
access_log logs/access.log combined;
Context: httpserverlocationif in locationlimit_except(不同版本此處略有不同

 

log_format

語法: log_format name format [format ...]

默認值: log_format combined "..."

作用域: http server

Directive log_format describes the format of a log entry. Besides general variables in the format it is possible to use variables which exist only at the moment of record into the log:

  • $body_bytes_sent, the number of bytes, transmitted to client minus the response headers, variable is compatible with parameter %B of module Apache's mod_log_config (this was called $apache_bytes_sent, before version 0.3.10)
  • $bytes_sent, the number of bytes, transmitted to client
  • $connection, the number of connection
  • $msec, the time with an accuracy to microseconds at the moment of the log entry
  • $pipe, "p" if request was pipelining
  • $request_length, the length of the body of the request
  • $request_time, the time of working on request in seconds
  • $status, status of answer
  • $time_local, local time into common log format.

The headers, transmitted to client, begin from the prefix "sent_http_", for example, $sent_http_content_range.

In the configuration there is always a predetermined format "combined":

 

log_format  combined  '$remote_addr - $remote_user [$time_local]  '
: '"$request" $status $apache_bytes_sent '
: '"$http_referer" "$http_user_agent"';

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章