Apache和Nginx开启访问日志但不记录图片css等的方法

[ 2014-05-24 14:26:42 | 作者: admin ]
字号: | |
nginx
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" $http_x_forwarded_for';

       location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
         {
                expires 30d;
                access_log off;
         }

         location ~ .*\.(js|css)?$
         {
                expires 1d;
                access_log off;
         }
         access_log /www/logs/xxx.com.log access;


apache下两种方式:
1.只记录html,htm,php等文件
SetEnvIfNoCase Request_URI "(\.htm|\/|\.html|\.php)$" htm
CustomLog logs/xxx.com-access_log combined env=htm

2.排除法:
<FilesMatch “\.(ico|gif|jpg|png|bmp|swf|js|css)”>
SetEnv IMAGE 1
</FilesMatch>
CustomLog logs/xxx.com-access_log combined env=!IMAGE




apache虚拟主机的实例
NameVirtualHost 192.168.2.187:80

<VirtualHost 192.168.2.187:80>
ServerAdmin webmaster@b.test.com
DocumentRoot /home/test
ServerName www.test.com
ErrorDocument 404 http://192.168.2.187/index.html
DirectoryIndex index.html index.jsp
<FilesMatch "\.(bmp|gif|jpg|swf)">
SetEnv IMAG 1
</FilesMatch>
CustomLog /var/wwwlogs/b.test.com.log combined env=!IMAG
<Directory />
         Options FollowSymLinks Indexes
         AllowOverride None
</Directory>
</VirtualHost>
[最后修改由 admin, 于 2014-05-24 14:34:55]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=2197

这篇日志没有评论。

此日志不可发表评论。