码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx 指定不产生日志类型(不记录图片日志)

时间:2016-12-01 22:57:34      阅读:2230      评论:0      收藏:0      [点我收藏+]

标签:nginx 指定不产生日志类型

在主配置文件中已经定义了配置文件的格式

[root@LNMP ~]# vim /usr/local/nginx/conf/nginx.conf  # nginx 中的配置修改 日志命名格式


 log_format combined_realip ‘$remote_addr $http_x_forwarded_for [$time_local]‘

  ‘$host "$request_uri" $status‘

    ‘"$http_referer" "$http_user_agent"‘;


$remote_addr # 远程的IP  $http_x_forwarded_for #代理的IP  

[$time_local] # 时间  ‘$host  域名  "$request_uri # 访问的地址    $status‘# 状态


combined_realip 这个格式名是可以自定义的。此处楼主改为了 “linux” ,在虚拟配置文件中使用


[root@LNMP ~]# vim /usr/local/nginx/conf/vhosts/linux.conf 

server

{

    listen 80;

    server_name www.linux.com www.test.com;

    if ($host !=‘www.linux.com‘)

    {

       rewrite ^/(.*)$ http://www.linux.com/$1 permanent;

    }

    index index.html index.htm index.php;

    root /data/dis;

    access_log /usr/local/nginx/logs/access.log linux;


access_log /usr/local/nginx/logs/access.log linux;  在linux.conf 中加入这一行代码。

技术分享

[root@LNMP ~]# /usr/local/nginx/sbin/nginx -t


[root@LNMP ~]# /usr/local/nginx/sbin/nginx -s reload



[root@LNMP ~]# curl -x127.0.0.1:80 www.test.com/kkkiiiillll  # 产生访问日志,查看日志


技术分享

上图中 箭头所示的 png,gif 等等这些网站的素材图片是可以不需要记录访问日志的,因为没有做限制,所以可以看到访问日志。那么接下来,我们可以根据需要设置,记录我们需要的日志。

 location 是有先后顺序的,要注意,有可能先的匹配了,就不再往下执行了。

[root@LNMP ~]# vim /usr/local/nginx/conf/vhosts/linux.conf #在 用户认证下面加入以下代码

 

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

    {

          access_log off;

    }

    location ~(static|cache)

    {

             access_log off;

    }


保存退出后,检测配有没有问题,然后重新加载nginx .


[root@LNMP ~]# > /usr/local/nginx/logs/access.log   #清空log 日志记录,以便区分

再次刷新论坛网页。已经png ,gif ,jpg 等等图片文件的访问日志已经没有了,同上图比较。

技术分享



本文出自 “CBO#Boy_Linux之路” 博客,请务必保留此出处http://20151213start.blog.51cto.com/9472657/1878587

Nginx 指定不产生日志类型(不记录图片日志)

标签:nginx 指定不产生日志类型

原文地址:http://20151213start.blog.51cto.com/9472657/1878587

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!