ngx_http_log_module 模块通过指定的格式把请求写入日志.
请求登陆到location处理结束的环境中.如果重定向发生在请求处理过程中,这或许与location原理不同.

Example Configuration

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

access_log /spool/logs/nginx-access.log compression buffer=32k;

Directives

Syntax: access_log path [format [buffer=size [flush=time]] [if=condition]];
access_log path format gzip[=level] [buffer=size] [flush=time] [if=condition];
access_log syslog:server=address[,parameter=value] [format [if=condition]];
access_log off;
Default:
access_log logs/access.log combined;
Context: http, server, location, if in location, limit_except

设置path,format,和配置写入日志的缓存,几个日志可以指定相同的级别.日志记录在syslog可以通过指令前缀"syslog:"在第一个参数,特殊值off 取消所有access_log指令在当前的级别.
如果format没有指定,那么预先定义的"combined"格式被使用.
如果buffer或gzip之一参数被使用,将缓冲写入日志。
buffer size 必须不能超过一个atomic write 磁盘文件中, FreeBSD这个size无限制的.
如果buffering 开启,数据将被写入到文件中:
如果下一行日志没有正确的进入buffer.
如果缓存数据时间比指定的flush参数更旧
当一个worker process 重新打开日志文件,或者关闭.
如果gzip参数被使用,那么缓存数据在写入文件前将被压缩.压缩级别可以被设置为1(快速,低压缩)到9(慢速,高压缩).默认,buffer大写是64kB,压缩级别为1,当数据被压缩原子块,日志文件可以被解压,或者使用zcat在任何时间查看.
Example:
access_log /path/to/log.gz combined gzip flush=5
使用gzip去压缩,nginx必须编译zlib库

文件路径可以包含变量,但是这样的日志有一些约束:
worker processes 所使用的凭证用户必须拥有日志文件目录的权限去创建文件.
缓冲写不工作
日志写入的文件被打开和关闭.然而,因为常用文件的描述符可以被存储在缓存中.指定了open_log_file_cache指令valid参数,在指定的时间写入到老的文件中.
当请求的root directory检测存在的就写入日志,不存在不写入日志.
因此一个更好的主意就是将root和access_log写入在相同的级别
server {
root /spool/vhost/data/$host;
access_log /spool/vhost/logs/$host;
...
if参数可以启用条件日志记录.请求将不会被记入日志,如果 condition 为 0或者空值.下边的例子,这个请求将返回2xx和3xx的错误代码,不会被记入log
map $status $loggable {
~^[23] 0;
default 1;
}

access_log /path/to/access.log combined if=$loggable;

Syntax: log_format name string ...;
Default:
log_format combined "...";
Context: http

log format

指定log的格式.
log fomat 可以包含普通的变量,并且这些变量只有在写log的时候存在.

$bytes_sent
the number of bytes sent to a client
$connection
connection serial number
$connection_requests
the current number of requests made through a connection (1.1.18)
$msec
time in seconds with a milliseconds resolution at the time of the log write
$pipe
“p” if request was pipelined, “.” otherwise
$time_iso8601
local time in the ISO 8601 standard format
$time_local
local time in the Common Log Format
发给客户端的首部行拥有一个前缀"sent_http_",例如,$sent_http_content_range.
配置总是包括预定义的"combined"格式:
log_format combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';

Syntax: open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];
open_log_file_cache off;
Default:
open_log_file_cache off;
Context: http, server, location

定义了缓存存储经常使用日志的文件描述符,这些名字包含变量.指令拥有下边这些参数

max
设置cache最大的数.如果cache将要满的时候 描述符将关闭
inactive
sets the time after which the cached descriptor is closed if there were no access during this time; by default, 10 seconds
min_uses
sets the minimum number of file uses during the time defined by the inactive parameter to let the descriptor stay open in a cache; by default, 1
valid
sets the time after which it should be checked that the file still exists with the same name; by default, 60 seconds
off
disables caching
Usage example:

open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;

Nginx log的更多相关文章

  1. nginx log的json格式:

    nginx log的json格式: 为了elk便于统计: yum安装nginx: log_format json '{"@timestamp": "$time_iso86 ...

  2. Nginx Log日志统计分析常用命令

    IP相关统计 统计IP访问量(独立ip访问数量) awk '{print $1}' access.log | sort -n | uniq | wc -l 查看某一时间段的IP访问量(4-5点) gr ...

  3. nginx log记录请求的头信息

    记录访问的log,为了在出现特殊情况时,方便检查出现问题的地方.log_format accesslog ‘$remote_addr – $remote_user [$time_local] “$re ...

  4. Python分析NGINX LOG版本二

    不好意思,上一版逻辑有错误,(只分析了一次就没了) 此版改正. 按同事要改,作成传参数形式,搞定. #!/usr/bin/env python # coding: utf-8 ############ ...

  5. nginx log日志分割

    @echo offrem 备份并根据时间重命名错误日志文件set "cmdstr=move E:\nginx\logs\error.log E:\nginx\logs\error%date: ...

  6. windows 下 nginx log 分割

    默认 nginx 不支持 log自动分割     windows下 解决方案:    1.首先创建bat脚本 split_log.bat , 并保存在nginx 目录下: @echo off rem ...

  7. Nginx log日志参数详解

    $args #请求中的参数值$query_string #同 $args$arg_NAME #GET请求中NAME的值$is_args #如果请求中有参数,值为"?",否则为空字符 ...

  8. Nginx log日志切割shell

    #!/bin/bash#此脚本用于自动分割Nginx的日志,包括access.log和error.log#每天00:00执行此脚本 将前一天的access.log重命名为access-xxxx-xx- ...

  9. nginx log 错误502 upstream sent too big header while reading response header from upstream

    cookies的值超出了范围我是说 看看了一下日志 错误502 upstream sent too big header while reading response header from upst ...

随机推荐

  1. 转:Redis 的安装配置介绍

    redis 是一个高性能的key-value数据库. redis的出现,很大程度补偿了memcached这类keyvalue存储的不足,在部 分场合可以对关系数据库起到很好的补充作用.它提供了Pyth ...

  2. 直接引用windows命名空间

    再逛博客的时候,看见一段这样代码.获取系统密码的 static void DumpCredentials(Windows.Security.Credentials.PasswordCredential ...

  3. angular-fullstack test

    1:运行yo 提示我可以升级到1.4.7版本,下面进行升级 提示需要npm>=2.8.0下面进行升级npm y@y:angular-fullstack-test$ npm install npm ...

  4. ListView OnScrollListener详解(滑屏分页显示数据)

    package com.action; import java.util.ArrayList; import java.util.List; import android.app.Activity; ...

  5. 14.4.4 Redo Log Buffer

    14.4.4 Redo Log Buffer redo log buffer 是内存区域持有数据被写入到redo log. Redo log buffer size 是通过 innodb_log_bu ...

  6. PL/SQL 动态SQL

    declare msql varchar2(200); row_id varchar2(200); begin loop row_id := 'AAATGiAAEAAAuLLAAA'; msql := ...

  7. 多线程同步、异步(BeginInvoke)

    一.线程的基础知识 1 System.Threading.Thread类 System.Threading.Thread是用于控制线程的基础类,通过Thread可以控制当前应用程序域中线程的创建.挂起 ...

  8. CentOS环境下,gdb调试中出现:Missing separate debuginfos, use: debuginfo-install.....的问题

    在gdb调试时segmentation fault问题时,遇到下面的了问题: Program received signal SIGABRT, Aborted.0x00007ffff73eb925 i ...

  9. 格式化字符串format函数

    自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式化字符串相比,有什么优越的存在呢?让我们来揭开它羞答答的面纱. 语法 它通过{}和 ...

  10. XSLT学习

    XSL 语言 XSL(eXtensible Stylesheet Language)是可扩展样式表语言,是一种用于以可读格式呈现 XML(标准通用标记语言的子集)数据的语言. XSL与xml CSS ...