Nginx处理cookie

六月 22nd, 2010 Posted in Nginx | 阅读次数: 439 次

群众的力量是巨大的,群众的智慧是无穷的。其实这次的需求就让我体会到这句话的意义。
现有一需求,需要把我们手机网站的cookie信息记录到access.log里,数据挖掘部门需要根据这个来统计用户行为。其实我还真没有这样记录过日志,后来百度了一下,发现Nginx确实很强大。

具体实现看配置:

server
{
        listen       80;
        server_name  192.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_pass  127.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_format  wap_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.log  wap_access;
}

 

其实从这个小小的需求里边得到的经验远远不止于此,这个就是为什么我的标题不叫nginx日志记录cookie的原因,请大家自己体会!

 

原文:http://blog.izhoufeng.com/posts/147.html

相关日志:

Tags:

6 Responses to “Nginx处理cookie”

  1. Pregnancy Miracle Review Says:

    New Websites I Like…

    [...]below you’ll find my recommended links page http://www.pregnancymiraclez.net/my-favourite-sites/ with some fantastic websites that I think you should definitely visit[...]…


  2. Related Resources Says:

    Related Websites…

    [...]here are some other links to sites that we find everyday so here are some popular sites we like today[...]…


  3. Resources Says:

    Interesting Posts…

    [...]some other related resources on the web that are worth viewing on this subject include[...]…


  4. hemorrhoid treatment Says:

    Related Websites…

    [...]here are some other links to sites that we find everyday so here are some popular sites we like today[...]…


  5. MSC Christmas Cruise Says:

    You should check this out……

    [...] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well [...]………


  6. ad networks Says:

    Check this out……

    [...] that is the end of this article. Here you’ll find some sites that we think you’ll appreciate, just click the links over[...]………


留下您的脚印