如果你对nginx日志格式,有这样那样的要求。

那么就看一下说明吧。

$remote_addr        The remote host
$remote_user The authenticated user (if any)
$time_local The time of the access
$request The first line of the request
$status The status of the request
$body_bytes_sent The size of the server's response, in bytes
$http_referer The referrer URL, taken from the request's headers
$http_user_agent The user agent, taken from the request's headers

如果你想记录某个cookie或者header里面的值的话

$cookie_[COOKIE_NAME]
$http_[HEADER_NAME]

我们来看下面的测试配置:

http {
include mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user $server_name [$time_local] "$request" '
'$status $body_bytes_sent "$request_body" "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "clickpid=$cookie_clickpid" "clickaid=$cookie_clickaid"'; access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 8080;
server_name localhost; #charset koi8-r; access_log logs/host.access.log main; location ~ \.php$ {
       #这里会记录post数据
access_log logs/post.log main;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1;
} location / {
       #这里不会记录post数据 
root html;
index index.html index.htm;
}

The significance of this variable appears in locations with directives proxy_pass or fastcgi_pass.

只有在用了proxy_pass或者fastcgi_pass标记的location{ }里面变量$request_body才会生效。

可参考:

http://www.cnblogs.com/meteorx/p/3188647.html

另外,还可以参考:

http://articles.slicehost.com/2010/8/27/customizing-nginx-web-logs

日志滚动,可以参考:

http://linux008.blog.51cto.com/2837805/555829/  使用logrotate

或者手动写脚本crontab 来执行:

#!/bin/sh

mv /usr/local/Cellar/nginx/1.6./logs/host.access.log /usr/local/Cellar/nginx/1.6./logs/host.access.log.2015.4.
kill -USR1 `cat /usr/local/var/run/nginx.pid`
sleep

这里mv需要自己判断是否存在重名文件。

nginx日志配置(cookie,header,post等字段记录)的更多相关文章

  1. nginx日志配置

    nginx日志配置 http://www.ttlsa.com/linux/the-nginx-log-configuration/ 日志对于统计排错来说非常有利的.本文总结了nginx日志相关的配置如 ...

  2. (转)nginx日志配置指令详解

    这篇文章主要介绍了nginx日志配置指令详解,nginx有一个非常灵活的日志记录模式,每个级别的配置可以有各自独立的访问日志,需要的朋友可以参考下日志对于统计排错来说非常有利的.本文总结了nginx日 ...

  3. Nginx https加密以及nginx日志配置与管理

    Nginx https加密以及nginx日志配置与管理 使用Nginx的优点Nginx作为WEB服务器,Nginx处理静态文件.索引文件.自动索引的效率非常高.Nginx作为代理服务器,Nginx可以 ...

  4. nginx日志配置指令详解

    这篇文章主要介绍了nginx日志配置指令详解,nginx有一个非常灵活的日志记录模式,每个级别的配置可以有各自独立的访问日志,需要的朋友可以参考下日志对于统计排错来说非常有利的.本文总结了nginx日 ...

  5. 死磕nginx系列-nginx日志配置

    nginx access日志配置 access_log日志配置 access_log用来定义日志级别,日志位置.语法如下: 日志级别: debug > info > notice > ...

  6. 03 . Nginx日志配置及日志切割

    Nginx日志 日志对于统计排错来说是非常有利的,Nginx日志主要分为两种: access_log(访问日志)和error_log(错误日志),通过访问日志可以得到用户的IP地址.浏览器的信息,请求 ...

  7. 004.Nginx日志配置及状态监控

    一 Nginx请求简介 1.1 请求头部 对于HTTP而言,客户端负责发起request请求,服务端负责response响应. request:包括请求行.请求头部.请求数据: response:包括 ...

  8. Nginx日志配置及日志分析脚本案例

    https://blog.csdn.net/bbwangj/article/details/82186162 nginx的log日志分为access log 和 error log 其中access ...

  9. nginx日志配置[转]

     * * * sh /home/zyf/sh/cut_nginx_log.sh 这样就每天的0点1分把nginx日志重命名为日期格式,并重新生成今天的新日志文件。 日志对于统计排错来说非常有利的。本文 ...

随机推荐

  1. array2json

    原文:jQuery方法扩展:type, toJSON, evalJSON. http://zhkac.iteye.com/blog/499330 .2013-05-19 (function($) { ...

  2. Python入门教程 超详细1小时学会Python

    Python入门教程 超详细1小时学会Python 作者: 字体:[增加 减小] 类型:转载 时间:2006-09-08我要评论 本文适合有经验的程序员尽快进入Python世界.特别地,如果你掌握Ja ...

  3. Ubuntu 安装HBase

    下载:http://mirror.bit.edu.cn/apache/hbase/stable/ 官方指南:http://abloz.com/hbase/book.html 安装配置: 解压: tar ...

  4. PHP flock() 函数 php中的文件锁定机制

    举一个例子: 假设一个文件读取的过程,有数万人在同时操作,那么极可能a用户刚刚写入,b用户也写入了,两者以至于混乱,或者在读取的时候,读取到别人写的数据.就好比上公共厕所,去厕所的时候要把门给打开上, ...

  5. linux - camera capture

    //cut a picture#include <stdio.h>#include <stdlib.h>#include <string.h>#include &l ...

  6. RabbitMQ之远程过程调用(RPC)【译】

    在第二个教程中,我们学习了如何使用工作队列在多个worker之间分配耗时的任务. 但是如果我们需要在远程计算机上运行功能并等待结果呢?嗯,这是另外一件事情,这种模式通常被称为远程过程调用(RPC). ...

  7. #!/bin/sh与#!/bin/bash的区别

    Linux 中的 shell 有很多类型,其中最常用的几种是: Bourne shell (sh).C shell (csh) 和 Korn shell (ksh), 各有优缺点.Bourne she ...

  8. node.js之web开发 koa入门

    用Node.js开发Web服务器端,有几个显著的优势: 速度快,非常快!这得益于Node.js天生是异步的. 常见的Web框架包括:Express,Sails.js,koa,Meteor,DerbyJ ...

  9. 原生sqlServer数据库连接

    package tj.test.demo; import java.sql.DriverManager;import java.sql.SQLException;import java.sql.Sta ...

  10. js学习笔记25----Event对象

    Event : 事件对象,当一个事件发生的时候,和当前这个对象发生的这个事件有关的一些详细的信息都会被临时保存到一个指定的地方-event 对象,供我们在需要时调用. 事件对象必须在一个事件调用的函数 ...