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 ...
随机推荐
- js blog
http://www.csdn.net/article/2013-12-16/2817820-javascript-survey-results 近日DailyJS社区发起了一项针对JavaScrip ...
- Windows平台下主要的内存管理途径
new / delete malloc / free CoTaskMemAlloc / CoTaskMemFree IMalloc::alloc / IMalloc/free G ...
- COJN 0487 800301红与黑
800301红与黑 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 有一间长方形的房子,地上铺了红色.黑色两种颜色的正方形瓷砖. ...
- 在Excel中将数字设置成文本格式的技巧
在Excel中将数字设置成文本格式的技巧 一个简单的方法,利用[数据]菜单的[分列]功能来将数字设置为文本格式.具体操作步骤为: 1.选中所有需要处理的数字单元格. 2.选择[数据]菜单[分列]功能. ...
- 【宽搜】【并查集】Vijos P1015 十字绣
题目链接: https://vijos.org/p/1015 题目大意: n*m的网格,线只能在网格的顶点处才能从布的一面穿到另一面.每一段线都覆盖一个单位网格的两条对角线之一,而在绣的过程中,一针中 ...
- Merge Sorted Array——LeetCode
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note:You may assume tha ...
- cryptopp开源库的使用(零):windows下使用visual studio编译
编译相当简单:打开目录下的sln文件直接编译即可,官方支持到vc2012,我使用vs2013也没有错误,优秀的开源库总是便于使用. 编译的时候注意运行库得选择需要跟使用该库的保持一致,否则会出现重定义 ...
- hdu-1242 dfs+各种剪枝
思路: 可以和1010一个思路.这个抽象的说就是让你求给定图中两点的最短距离,其实dfs的题目能变化的地方就在“终点的回溯处”,在我们到达终点后,再判断一些附加的值(本题里是最短距离是否更新),从而得 ...
- 自定义UINavigationItem的两种方法以及相应的隐藏方法
第一种: UIImage *searchimage=[UIImage imageNamed:@"search.png"]; UIBarButtonItem *barbtn=[[[U ...
- c# 根据自定义Attribute排序
add a class: public class ExportAttribute : Attribute { public int FieldOrder { get; set; } ...