Nginx log
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的更多相关文章
- nginx log的json格式:
nginx log的json格式: 为了elk便于统计: yum安装nginx: log_format json '{"@timestamp": "$time_iso86 ...
- Nginx Log日志统计分析常用命令
IP相关统计 统计IP访问量(独立ip访问数量) awk '{print $1}' access.log | sort -n | uniq | wc -l 查看某一时间段的IP访问量(4-5点) gr ...
- nginx log记录请求的头信息
记录访问的log,为了在出现特殊情况时,方便检查出现问题的地方.log_format accesslog ‘$remote_addr – $remote_user [$time_local] “$re ...
- Python分析NGINX LOG版本二
不好意思,上一版逻辑有错误,(只分析了一次就没了) 此版改正. 按同事要改,作成传参数形式,搞定. #!/usr/bin/env python # coding: utf-8 ############ ...
- nginx log日志分割
@echo offrem 备份并根据时间重命名错误日志文件set "cmdstr=move E:\nginx\logs\error.log E:\nginx\logs\error%date: ...
- windows 下 nginx log 分割
默认 nginx 不支持 log自动分割 windows下 解决方案: 1.首先创建bat脚本 split_log.bat , 并保存在nginx 目录下: @echo off rem ...
- Nginx log日志参数详解
$args #请求中的参数值$query_string #同 $args$arg_NAME #GET请求中NAME的值$is_args #如果请求中有参数,值为"?",否则为空字符 ...
- Nginx log日志切割shell
#!/bin/bash#此脚本用于自动分割Nginx的日志,包括access.log和error.log#每天00:00执行此脚本 将前一天的access.log重命名为access-xxxx-xx- ...
- 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 ...
随机推荐
- 转:OWASP发布Web应用程序的十大安全风险
Open Web Application Security Project(OWASP)是世界范围内的非盈利组织,关注于提高软件的安全性.它们的使命是使应用软件更加安全,使企业和组织能够对应用安全风险 ...
- GitHub NetFlow
https://github.com/search?l=Java&p=1&q=netflow&ref=searchresults&type=Repositories&a ...
- RandomAccessFile和memory-mapped files
[0]README 0.1) 本文描述转自 core Java volume 2, 旨在理解 java流与文件——RandomAccessFile类解析 的相关知识: 0.1) 本文 转自: http ...
- mybatis insertUseGeneratedKeys
mybatis中的一个坑:预期:传入的Record中会生动填入在db中生成的id值. 使用 insertUseGeneratedKeys插入数据时,如果id字段不是AUTO_INCREMENT,则不 ...
- COJ 0985 WZJ的数据结构(负十五)(限定区域不同数)
传送门:http://oj.cnuschool.org.cn/oj/home/addSolution.htm?problemID=955 试题描述: CHX有一个问题想问问大家.给你一个长度为N的数列 ...
- 维基百科上—数据仓库、数据挖掘、OLAP三者之间的区别
数据仓库可以作为数据挖掘和OLAP等分析工具的资料来源,由于存放于数据仓库中的资料,必需经过筛选与转换,因此可以避免分析工具使用错误的资料,而得到不正确的分析结果. 数据挖掘和OLAP同为分析工具,其 ...
- 【转】TCP三次握手过程
写的非常明白:http://www.cnblogs.com/rootq/articles/1377355.html TCP协议三次握手过程分析 TCP(Transmission Control Pro ...
- adb getprop setprop watchprop用法
在android系统中,有一些初始化的配置文件,例如: /init.rc /default.prop /system/build.prop 文件里面里面配置了开机设置的系统属性值,这些属性值,可以通过 ...
- Apache-Tika解析PDF文档
通常在使用爬虫时,爬取到网上的文章都是各式各样的格式处理起来比较麻烦,这里我们使用Apache-Tika来处理PDF格式的文章,如下: package com.mengyao.tika.app; im ...
- Linux操作系统以及各大发行版介绍——Linux operating system and major distribution is introduced
什么是Linux? 也许很多人会不屑的说,Linux不就是个操作系统么.错!Linux不是一个操作系统,严格来讲,Linux只是一个操作系统中的内核.内核是什么?内核建立了计算机软件与硬件之间通讯的平 ...