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 ...
随机推荐
- cf C. Divisible by Seven
http://codeforces.com/contest/376/problem/C 题意:给你一个大数最多含有10^6个数字,这里面必须含有1,6,8,9,然后重新排列找出一个能被6整除的数. 思 ...
- Expanding Rods
http://poj.org/problem?id=1 #include<cstdio> #include<cstring> #include<cmath> #in ...
- SQLite for xamarin
原文地址:http://www.codeproject.com/Articles/1097179/SQLite-with-Xamarin-Forms-Step-by-Step-guide SQLite ...
- Android 有趣味的GridView
工作这么久以来,都是以解决需求为目标.渐渐发现这种学习方式不好,学到的知识能马上解决问题,但没有经过梳理归纳.故想系统总结下一些有趣味的知识点.在这篇博客中想以一个例子系统讲解下GridView控件涉 ...
- Javascript的IE和Firefox兼容性汇编
以下以 IE 代替 Internet Explorer,以 MF 代替 Mozzila Firefox 1. document.form.item 问题 (1)现有问题: 现有代码 ...
- activitie用户手册
最近公司开发流程,学习流程开发,不停看api学习.这是做软件的额...不停的学习学习!!!天天进步中! 用户手册地址:http://www.mossle.com/docs/activiti/#acti ...
- 使用 VMAccess 扩展程序重置 Linux 虚拟机的登录凭据
Ning KuangWSSC WS ARD高级项目经理 您是否曾经因为忘记 Azure VM 密码或 SSH密钥而导致无法访问 VM?VMAccess扩展程序使您可以重置密码.SSH密钥或 SSH ...
- 维基百科上—数据仓库、数据挖掘、OLAP三者之间的区别
数据仓库可以作为数据挖掘和OLAP等分析工具的资料来源,由于存放于数据仓库中的资料,必需经过筛选与转换,因此可以避免分析工具使用错误的资料,而得到不正确的分析结果. 数据挖掘和OLAP同为分析工具,其 ...
- 向Int数组插入随机1到100
这是一个经典的面试题,考察了几个知识点 下边的代码是传统经典的做法 ]; ArrayList myList=new ArrayList(); Random rnd=new Random(); ) { ...
- 关于sql server 代理(已禁用代理xp)解决办法
master数据库下执行 sp_configure 'show advanced options', 1; GO RECONFIGURE; GO sp_configure 'Agent ...