Nginx了解访问日志列

Dew*_*rld 26 logging nginx

我理解这个应用程序访问日志的所有列 - IP,日期,请求,响应代码和......除了下一列是我不理解的(在下面的例子中,177,4223,4356).这是什么意思?

66.249.65.159 - - [06/Nov/2014:19:10:38 +0600] "GET /news/53f8d72920ba2744fe873ebc.html HTTP/1.1" 404 177 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
66.249.65.3 - - [06/Nov/2014:19:11:24 +0600] "GET /?q=%E0%A6%AB%E0%A6%BE%E0%A7%9F%E0%A6%BE%E0%A6%B0 HTTP/1.1" 200 4223 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
66.249.65.62 - - [06/Nov/2014:19:12:14 +0600] "GET /?q=%E0%A6%A6%E0%A7%8B%E0%A7%9F%E0%A6%BE HTTP/1.1" 200 4356 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
Run Code Online (Sandbox Code Playgroud)

编辑:我用谷歌搜索,但找不到任何答案.

ste*_*els 34

"响应代码"(即状态)之后的列是"发送的字节数".

nginx中的默认日志格式称为"组合".它等同于以下配置.

# nginx.conf
http {
  ...
  log_format combined '$remote_addr - $remote_user [$time_local] '
                      '"$request" $status $body_bytes_sent '
                      '"$http_referer" "$http_user_agent"';
  ...
}
Run Code Online (Sandbox Code Playgroud)

来源:模块ngx_http_log_module

  • 感谢您实际上包含了“组合”的定义。其他答案只是提到了“组合”这个名称,而没有定义它,这使得答案对我来说毫无用处。 (8认同)

Eyn*_*ave 6

NGINX 日志变量文档

在此链接中,您可以找到可在 nginx 日志记录中使用的所有可能的变量及其描述......

此外,您可以配置 nginx 使用您喜欢的模板创建自定义日志:

  1. 编辑/etc/nginx/nginx.conf

  2. find 'access_log' lines

  3. before this line, define your logging template(like below for example):

    log_format firelog '$status "$time_local" client=$remote_addr ' 'method=$request_method request="$request" ' 'request_length=$request_length ' 'status=$status bytes_sent=$bytes_sent ' 'body_bytes_sent=$body_bytes_sent ' 'referer=$http_referer ' 'user_agent="$http_user_agent" ' 'upstream_addr=$upstream_addr ' 'upstream_status=$upstream_status ' 'request_time=$request_time ' 'upstream_response_time=$upstream_response_time ' 'upstream_connect_time=$upstream_connect_time ' 'upstream_header_time=$upstream_header_time ' 'body=$request_body';

  4. then update access line like below:

    access_log /var/log/nginx/firelog.log firelog;

  5. Almost done! Just test configuration with nginx -t command

  6. service nginx restart