1、编辑主配置文件

vim /usr/local/nginx/conf/nginx.conf

2、将log_format combined_realip改为log_format river

备注:日志格式各项参数含义:$remote_addr(远程主机地址)$http_x_xforwarded_for(代理ip)$host"erquest_rui"(访问的地址链接)status(状态码)$http_referer(referer)$http_user_agent(useragent)

3、编辑虚拟主机配置文件

vim /usr/local/nginx/conf/vhosts/test.conf 

4、添加以下配置

access_log /tmp/access.log river;(river为上面定义的日志名)

5、重新加载配置文件

/usr/local/nginx/sbin/nginx -s reload

6、使用curl访问

curl -x127.0.0.1:80 www.bbb.com/1111111 -I

可以查看/tmp下已经有access.log文件

7、在配置文件添加以下行

 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

    {

        access_log off;

}

    location ~ (static|cache)

    {

        access_log off;

}

8、重新加载后再刷新论坛页面几次查看日志已经没有记录指定类型的文件的日志记录也没有记录含有static和cache的记录