zoukankan      html  css  js  c++  java
  • 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需要自己判断是否存在重名文件。

  • 相关阅读:
    集合set() 和 深浅copy
    Python 数据类型的操作——字典
    Python()- 面向对象
    面向对象的软件开发
    Python数据类型的操作——列表、元组
    Python 数据类型的操作——字符串
    Linux下386中断处理
    任务的休眠与唤醒
    Linux下SIGSTOP的特殊特征和实现
    内核线程对信号的处理策略
  • 原文地址:https://www.cnblogs.com/zhangqingping/p/4390862.html
Copyright © 2011-2022 走看看