服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

dirtysea 发表于 2010-7-23 17:36:02

Nginx处理cookie

<P>群众的力量是巨大的,群众的智慧是无穷的。其实这次的需求就让我体会到这句话的意义。 <BR>现有一需求,需要把我们**网站的cookie信息记录到access.log里,数据挖掘部门需要根据这个来统计用户行为。其实我还真没有这样记录过日志,后来百度了一下,发现Nginx确实很强大。</P>
<P>具体实现看配置: </P><PRE>server
{
      listen       80;
      server_name192.168.1.101;
      #setting cookie log
        #if ( $http_cookie ~* "wap_auth=(.+)(?:;|$)" )
         if ( $http_cookie ~* "(.*)$")
      {
                set $wap_cookie $1;
      }
      index index.php index.htm index.html;
      add_header Load-Balancing $server_addr;
      root/server/www/apps/wap_v2;
      rewrite ^/css/(.*)$ /media/css/$1 last;

      location /logs {
                alias /data/nginx/logs/;
      }
      location ~* .*\.(php|html)?$
      {
                fastcgi_pass127.0.0.1:9000;
                fastcgi_index index.php;
                include fcgi.conf;
      }
      location /nginx-status {
                stub_status on;
                allow 192.168.1.171;
                deny all;
      }
      log_formatwap_access'$remote_addr $host \
          $server_addr [$time_local] "$request \
          " ' '$status $body_bytes_sent \
          "$http_referer" ' '"$http_user_agent\
          " "$wap_cookie"';
      access_log/data/nginx/logs/access_wap.logwap_access;
}</PRE>
<P>&nbsp;</P>
<P>其实从这个小小的需求里边得到的经验远远不止于此,这个就是为什么我的标题不叫nginx日志记录cookie的原因,请大家自己体会! </P>
页: [1]
查看完整版本: Nginx处理cookie