nginx日志配置(cookie,header,post等字段记录)

 

如果你对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.2/logs/host.access.log /usr/local/Cellar/nginx/1.6.2/logs/host.access.log.2015.4.3
kill -USR1 `cat /usr/local/var/run/nginx.pid`
sleep 1

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

 

转载于:https://www.cnblogs.com/zhangqingping/p/4390862.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值