天天看点

nginx不记录指定文件类型日志

1. 查看主配置文件定义的日志格式 /usr/local/nginx/conf/nginx.conf

   日志格式说明:

   combined_realip #表示日志格式名称,可自定义

   remote_addr #表示远程主机

   http_x_forwarded_for #表示代理ip

   time_local #表示时间

   host #表示域名

   request_uri #表示访问的地址

   status #状态码

   http_referer #表示referer

   http_user_agent #表示用户代理信息

<code>log_format combined_realip </code><code>'$remote_addr $http_x_forwarded_for [$time_local]'</code> <code>'$host "$request_uri" $status'</code> <code>'"$http_referer" "$http_user_agent"'</code><code>;</code>

2. 编辑虚拟主机配置文件 /usr/local/nginx/conf/vhosts/huangzhenping.conf

    说明:添加日志配置;用location匹配并过滤文件类型,如有多个location且内容有交集,按先后顺序执行

    加入:

<code>access_log </code><code>/tmp/access</code><code>.log combined_realip;</code>

<code>    </code><code>location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {</code>

<code>    </code><code>access_log off;</code>

<code>    </code><code>}</code>

<code>    </code><code>location ~ (static|cache)</code>

<code>    </code><code>{</code>

<code>      </code><code>access_log off;</code>

    /usr/local/nginx/sbin/nginx -t

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

本文转自 huangzp168 51CTO博客,原文链接:http://blog.51cto.com/huangzp/1900637,如需转载请自行联系原作者

继续阅读