介绍:项目中的CSS、图片、js都是静态文件。一般会将静态文件放到一个单独的目录中,以方便管理。

1. 配置

# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

ServerAdmin webmaster@dummy-host.example.com

DocumentRoot "/usr/local/apache2.4/docs/www.111.com"

ServerName www.111.com

ServerAlias 111.com

ErrorLog "logs/111.com-error_log"

CustomLog "logs/111.com-access_log" common

</VirtualHost>

上传图片文件到image中

# cd /usr/local/apache2.4/docs/www.111.com/

# mkdir image

# ll image/linux.jpg

检查配置信息

# /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful

# curl -xlocalhost:80 www.111.com/image/linux.jpg -I

查看日志

# tail -f /usr/local/apache2.4/logs/111.com-access_log

打开网页访问111.com/image/linux.jpg

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

ServerAdmin webmaster@dummy-host.example.com

DocumentRoot "/usr/local/apache2.4/docs/www.111.com"

ServerName www.111.com

ServerAlias 111.com

SetEnvIf Request_URI ".*\.gif$" image-request

SetEnvIf Request_URI ".*\.jpg$" image-request

SetEnvIf Request_URI ".*\.png$" image-request

SetEnvIf Request_URI ".*\.bmp$" image-request

SetEnvIf Request_URI ".*\.swf$" image-request

SetEnvIf Request_URI ".*\.js$" image- request

SetEnvIf Request_URI ".*\.css$" image- request

ErrorLog "logs/111.com-error_log"

CustomLog "logs/111.com-access_log" combined env=!image-request

</VirtualHost>

//先定义了一个image-request环境变量,把gif,jpg,png, bmp,swf,js,css等格式文件全归类到此,env=!image-request表示日志记录不为image-request中表示的静态文件。

保存配置后,测试配置文件是否正确,没有错误重新加载服务:

#/usr/local/apache2.4/bin/apachectl -t

Syntax OK

#/usr/local/apache2.4/bin/apachectl graceful

(2)配置验证

# curl -xlocalhost:80 www.111.com/image/linux.jpg -I

另打开一个窗口,查看日志,关于jpg格式的没有访问日志信息

# tailf   ../../logs/111.com-access_log

访问成功

Apache配置 5.访问日志不记录静态文件的更多相关文章

  1. Linux centos7 VMware Apache访问日志不记录静态文件、访问日志切割、静态元素过期时间

    一.Apache访问日志不记录静态文件 网站大多元素为静态文件,如图片.css.js等,这些元素可以不用记录 vim /usr/local/apache2.4/conf/extra/httpd-vho ...

  2. Apache配置 4.访问日志

    (1)介绍 访问日志作用很大,不仅可以记录网站的访问情况,还可以在网站有异常发生时帮助我们定位问题. (2)配置 # vi /usr/local/apache2.4/conf/extra/httpd- ...

  3. Spring Boot 2 配置服务器访问日志

    Tomcat控制台中看到的日志是服务器的日志,而服务器访问日志则是记录服务处理的请求信息. 开发环境:IntelliJ IDEA 2019.2.2Spring Boot版本:2.1.8 1.新建一个名 ...

  4. Apache日志不记录图片文件设置方法和来源日志的配置

    Apache日志不记录图片文件设置方法 <FilesMatch "\.(ico|gif|jpg|swf)">SetEnv IMAG 1</FilesMatch&g ...

  5. LNMP-Nginx配置不记录静态文件、过期时间

    用户访问web网站,通常日志文件会记录很多web站点上的一些静态文件信息,如果长期不处理,日志文件会越来越大,占用的系统资源也越大,此时就需要我们配置不记录静态文件和过期时间,减少日志文件记录过多不必 ...

  6. Nginx访问日志、 Nginx日志切割、静态文件不记录日志和过期时间

    1.Nginx访问日志 配制访问日志:默认定义格式: log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_loc ...

  7. apache配置禁止访问某些文件/目录

    我们来看俩段通常对上传目录设置无权限的列子,配置如下: 代码如下: ? 1 2 3 4 5 6 <Directory "/var/www/upload"> <Fi ...

  8. python统计apache、nginx访问日志IP访问次数并且排序(显示前20条)【转】

    前言:python统计apache.nginx访问日志IP访问次数并且排序(显示前20条).其实用awk+sort等命令可以实现,用awk数组也可以实现,这里只是用python尝试下.   apach ...

  9. Nginx访问日志、日志切割、静态文件不记录日志和过期时间

    6月8日任务 12.10 Nginx访问日志12.11 Nginx日志切割12.12 静态文件不记录日志和过期时间 12.10 Nginx访问日志 除了在主配置文件nginx.conf里定义日志格式外 ...

随机推荐

  1. 从网络I/O模型到Netty,先深入了解下I/O多路复用

    微信搜索[阿丸笔记],关注Java/MySQL/中间件各系列原创实战笔记,干货满满. 本文是Netty系列第3篇 上一篇文章我们了解了Unix标准的5种网络I/O模型,知道了它们的核心区别与各自的优缺 ...

  2. docker+prom+grafana+altermanager

    docker基础 docker run -it --name centos -v $HOME:/tmp -p 8080:8080 centos docker inspect container #查看 ...

  3. LINUX - 随机数

    #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h& ...

  4. java源码之集合类ArrayList

    1. ArrayList概述: ArrayList是List接口的可变数组的实现.实现了所有可选列表操作,并允许包括 null 在内的所有元素.除了实现 List 接口外,此类还提供一些方法来操作内部 ...

  5. python 表达式

    运算符 参考 https://www.runoob.com/python3/python3-basic-operators.html & https://www.runoob.com/pyth ...

  6. canvas绘制五星红旗

    代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8& ...

  7. Object 循环引用 All In One

    Object 循环引用 All In One circular reference bug var a = {}; a.a = a; refs deep copy bug https://segmen ...

  8. node.js 中间件

    node.js 中间件 node.js middleware Express middleware body-parser cookie-parser cookie-session cors csur ...

  9. js inheritance all in one

    js inheritance all in one prototype & proto constructor Object.definepropety Object.create() js ...

  10. export excel

    export excel sheet.js https://sheetjs.com/ https://github.com/SheetJS/sheetjs excel.js https://www.n ...