vzdsa 发表于 2015-8-13 10:44:36

LNMP--Nginx不记录指定文件日志

                      编辑Nginx配置文件:
# vim /usr/local/nginx/conf/nginx.conf
找到下面一行:
log_format combined_realip'$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
将内容更改为:
log_format linan'$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
编辑虚拟主机配置文件:
# vim /usr/local/nginx/conf/vhosts/test.conf
在 “root /data/www” 下面写入:

access_log /tmp/access.log linan;(红字用户名对应上面更改后的用户名)
检查并重加载:
# /usr/local/nginx/sbin/nginx -t
# /usr/local/nginx/sbin/nginx -s reload
刷新网页,我们查看日志:
# cat /tmp/access.log
发现记录了很多内容,其中图片信息没有必要去记录。
配置不记录指定文件日志:

编辑虚拟主机配置文件:
# vim /usr/local/nginx/conf/vhosts/test.conf
在"用户认证"配置下面写入:
location ~ .*\.(gif|jpg|png|jpeg|bmp|swf)$
      {
          access_log off;
      }
# /usr/local/nginx/sbin/nginx -t
# /usr/local/nginx/sbin/nginx -s reload
刷新网页,继续查看日志:
# cat /tmp/access.log

发现没有限制记录的图片了,但是还有js和css类型的图片没有禁止记录。
下面我们去配置,还是进入“虚拟主机配置文件”编辑,在上一段下面继续补充一段:
location ~ (static|cache)    # 限定static和cache,因为日志中观察到css和js都在这个目录下。
      {
          access_log off;
      }
# /usr/local/nginx/sbin/nginx -t
# /usr/local/nginx/sbin/nginx -s reload
刷新网页,查看日志:
# cat /tmp/access.log
不记录限制的图片文件了。
                   

页: [1]
查看完整版本: LNMP--Nginx不记录指定文件日志