关于nginx:Nginx-配置-access-log-请求日志详解

10次阅读

共计 1144 个字符,预计需要花费 3 分钟才能阅读完成。

配置示例

log_format main '$remote_addr - $remote_user [$time_local]'
                '"$request" $status $bytes_sent ''"$http_referer""$http_user_agent" "$http_x_forwarded_for"';

access_log logs/access.log main;

log_format 指令

默认值:log_format combined "...";

标签段地位:http

罕用变量:

  • $bytes_sent 发送给客户端内容的字节数,位于 ngx_http_log_module
  • $request_length 申请长度(包含申请行,标头和申请注释),位于 ngx_http_log_module
  • $request_time 要求以毫秒为单位的解决工夫,位于 ngx_http_log_module
  • $status 状态码,位于 ngx_http_log_module
  • $time_local 申请的本地工夫和市区,位于 ngx_http_log_module
  • $remote_addr 客户端地址,位于 ngx_http_core_module
  • $remote_user Basic 受权模式下的客户端用户名称,位于 ngx_http_core_module
  • $request 残缺的申请地址和协定,位于 ngx_http_core_module
  • $request_body 申请的 body 内容,位于 ngx_http_core_module
  • $http_host 域名或 IP
  • $http_referer 申请的跳转起源
  • $http_user_agent 浏览器信息
  • $http_x_forwarded_for 记录客户端地址的配置

如果变量对应的值不存在,则以“-”代替。

access_log 指令

默认值:access_log logs/access.log combined;

标签段地位:http, server, location, if in location, limit_except

access_log off;
access_log logs/access.log main;
access_log logs/access.log main buffer=32k flush=5s;
map $status $loggable {~^[23]  0;
    default 1;
}

# 非 2xx 和 3xx 的状态才写入日志
access_log /path/to/access.log main if=$loggable;

重载配置

../sbin/nginx -t
../sbin/nginx -s reload

参考:http://nginx.org/en/docs/http…

http://nginx.org/en/docs/http…

正文完
 0