日志不记录静态文件,日志切割,静态元素过期时间

访问日志不记录静态文件

1.过滤静态文件:修改虚拟主机配置文件

[[email protected] ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP_HOST} !^111.com$
        RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L]
   </IfModule>

    ErrorLog "logs/111.com-error_log"
    SetEnvIf Request_URI ".*\.gif$" img
    SetEnvIf Request_URI ".*\.jpg$" img
    SetEnvIf Request_URI ".*\.png$" img
    SetEnvIf Request_URI ".*\.bmp$" img
    SetEnvIf Request_URI ".*\.swf$" img
    SetEnvIf Request_URI ".*\.js$" img
    SetEnvIf Request_URI ".*\.css$" img
    CustomLog "logs/111.com-access_log" combined env=!img
</VirtualHost>

2.进行验证,重新加载:

[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful

3.测试:jpg1,jpg

[[email protected] ~]# curl -x127.0.0.1:80 111.com/alsdkjfakjg.jpg1  -I
HTTP/1.1 404 Not Found
Date: Mon, 05 Mar 2018 13:20:01 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
Content-Type: text/html; charset=iso-8859-1

[[email protected] ~]# tail /usr/local/apache2.4/logs/111.com-access_log
192.168.188.1 - - [03/Mar/2018:10:01:35 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:36 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:42 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 301 223 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:36 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:43 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:49 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
127.0.0.1 - - [05/Mar/2018:21:16:51 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
127.0.0.1 - - [05/Mar/2018:21:20:01 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg1 HTTP/1.1" 404 - "-" "curl/7.29.0"
[[email protected] ~]# curl -x127.0.0.1:80 111.com/alsdkjfak1231jg.jpg  -I
HTTP/1.1 404 Not Found
Date: Mon, 05 Mar 2018 13:20:24 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
Content-Type: text/html; charset=iso-8859-1

[[email protected] ~]# tail /usr/local/apache2.4/logs/111.com-access_log
192.168.188.1 - - [03/Mar/2018:10:01:35 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:36 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:42 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 301 223 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:36 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:43 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:49 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
127.0.0.1 - - [05/Mar/2018:21:16:51 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
127.0.0.1 - - [05/Mar/2018:21:20:01 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg1 HTTP/1.1" 404 - "-" "curl/7.29.0"
[[email protected] ~]# curl -x127.0.0.1:80 111.com/alsdkjfak1231jg.jpg12  -I
HTTP/1.1 404 Not Found
Date: Mon, 05 Mar 2018 13:20:48 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
Content-Type: text/html; charset=iso-8859-1

[[email protected] ~]# tail /usr/local/apache2.4/logs/111.com-access_log
192.168.188.1 - - [03/Mar/2018:10:01:36 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:42 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 301 223 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:01:51 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:36 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:43 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.188.1 - - [03/Mar/2018:10:02:49 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
127.0.0.1 - - [05/Mar/2018:21:16:51 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
127.0.0.1 - - [05/Mar/2018:21:20:01 +0800] "HEAD HTTP://111.com/alsdkjfakjg.jpg1 HTTP/1.1" 404 - "-" "curl/7.29.0"
127.0.0.1 - - [05/Mar/2018:21:20:48 +0800] "HEAD HTTP://111.com/alsdkjfak1231jg.jpg12 HTTP/1.1" 404 - "-" "curl/7.29.0"

访问日志切割


1.打开虚拟主机配置文件:

[[email protected] 111.com]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
    CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/111.com-access_%Y%m%d.log 86400" combined env=!img

2.重新加载:

[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl graceful

3.验证:

[[email protected] 111.com]# ls /usr/local/apache2.4/logs
111.com-access_log  abc.com-access_log  access_log  httpd.pid
111.com-error_log   abc.com-error_log   error_log
[[email protected] 111.com]# curl -x127.0.0.1:80 111.com/123.php
123.php[[email protected] 111^C
[[email protected] 111.com]# ls /usr/local/apache2.4/logs
111.com-access_20180305.log  111.com-error_log   abc.com-error_log  error_log
111.com-access_log           abc.com-access_log  access_log         httpd.pid
[[email protected] 111.com]# cat /usr/local/apache2.4/logs/111.com-access_20180305.log
127.0.0.1 - - [05/Mar/2018:21:51:50 +0800] "GET HTTP://111.com/123.php HTTP/1.1" 200 7 "-" "curl/7.29.0"

静态元素过期时间

304表示来自缓存
1.打开虚拟主机配置文件

[[email protected] 111.com]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
   </IfModule>
<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresByType image/gif  "access plus 1 days"
    ExpiresByType image/jpeg "access plus 24 hours"
    ExpiresByType image/png "access plus 24 hours"
    ExpiresByType text/css "now plus 2 hour"
    ExpiresByType application/x-javascript "now plus 2 hours"
    ExpiresByType application/javascript "now plus 2 hours"
    ExpiresByType application/x-shockwave-flash "now plus 2 hours"
    ExpiresDefault "now plus 0 min"
</IfModule>

2.重新加载

[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl graceful

3.检测模块是否开启,没有打开,修改主配置文件:

[[email protected] 111.com]# vim /usr/local/apache2.4/conf/httpd.conf
LoadModule env_module modules/mod_env.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
#LoadModule unique_id_module modules/mod_unique_id.so
[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl -M |grep expire
 expires_module (shared)

4.验证:有cache control一行

[[email protected] 111.com]# curl -x127.0.0.1:80 111.com/bj.jpg -I
HTTP/1.1 200 OK
Date: Mon, 05 Mar 2018 14:14:26 GMT
Server: Apache/2.4.29 (Unix) PHP/7.1.6
Last-Modified: Tue, 02 May 2017 15:30:36 GMT
ETag: "7e25-54e8c38a0bf00"
Accept-Ranges: bytes
Content-Length: 32293
Cache-Control: max-age=86400
Expires: Tue, 06 Mar 2018 14:14:26 GMT
Content-Type: image/jpeg

原文地址:http://blog.51cto.com/13517254/2083235

时间: 2024-10-27 12:37:11

日志不记录静态文件,日志切割,静态元素过期时间的相关文章

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

一.Nginx访问日志 日志格式 vim /usr/local/nginx/conf/nginx.conf //搜索log_format combined_realip //规则名字 除了在主配置文件nginx.conf里定义日志格式外,还需要在虚拟主机配置文件中增加 vim /usr/local/nginx/conf/vhost/test.com.conf 添加 access_log /tmp/1.log combined_realip; 这里的combined_realip就是在nginx.

访问日志不记录静态文件、访问日志切割、静态元素过期时间

访问日志不记录静态文件 当访问很多图片,文档等静态资源的时候,会加大你日志的容量,日志容量占用你磁盘空间后,会出现服务器宕机等很严重的问题,这时需要将日志进行配置优化.当访问网页时不记录这些图片.css.js等信息日志. 1.[[email protected] 111.com]# vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf <VirtualHost *:80> DocumentRoot "/data/wwwroot/11

LAMP架构(apache访问日志不记录静态文件,静态元素过期时间,apache日志切割)

一.apache访问日志不访问静态文件 浏览器打开后按f12会会出现一个界面,点network,会出现很多请求,访问日志里会记载,有些静态的图片或者文件也会记载,太浪费磁盘空间和磁盘io.所以我们要让日志不记录静态文件 [[email protected] ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf SetEnvIf Request_URI ".*\.gif$" img SetEnvIf Request_URI &

11.22 访问日志不记录静态文件;11.23 访问日志切割;11.24 静态元素过期时间

扩展: apache日志记录代理IP以及真实客户端IP : http://ask.apelearn.com/question/960 apache只记录指定URI的日志 : http://ask.apelearn.com/question/981 apache日志记录客户端请求的域名 : http://ask.apelearn.com/question/1037 apache 日志切割问题 : http://ask.apelearn.com/question/566 11.22 访问日志不记录静

11.22 访问日志不记录静态文件11.23 访问日志切割11.24 静态元素过期时间

11.22 访问日志不记录静态文件11.23 访问日志切割11.24 静态元素过期时间编辑虚拟配置文件:vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf11.23 访问日志切割修改完配置文件后,需要重新访问下网址才能生动生成日志文件,以后每到00:00就会自动生成以系统日期为名字的新的日志文件编辑虚拟配置文件:vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf修改完后重新加载配置文件

11.22 访问日志不记录静态文件 11.23 访问日志切割 11.24 静态元素过期时间

11.22 访问日志不记录静态文件 11.23 访问日志切割 11.24 静态元素过期时间 11.22 访问日志不记录静态文件 11.23 访问日志切割 11.24 静态元素过期时间 原文地址:http://blog.51cto.com/wbyyy/2083288

四十二、访问日志不记录静态文件、访问日志切割、静态元素过期时间

一.访问日志不记录静态文件 访问日志:可以记录网站的访问情况,还可以在网站有异常发生时帮助我们定位问题,比如当有攻击时,是可以通过查看日志看到一些规律的. 静态元素:一个网站有很多元素,比如图片.js.css等静态文件,这些就是静态元素.QQ浏览器,按F12可以查看它的静态元素,Network. 要配置httpd访问日志,首先需要虚拟主机配置文件中定义访问日志的格式,打开虚拟主机配置文件: # vim /usr/local/apache2.4/conf/extra/httpd-vhosts.co

11.22-11.24访问日志不记录静态文件,访问日志切割,静态元素过期时间

11.22 访问日志不记录静态文件 11.23 访问日志切割 11.24 静态元素过期时间 扩展 apache日志记录代理IP以及真实客户端IP  http://ask.apelearn.com/question/960apache只记录指定URI的日志  http://ask.apelearn.com/question/981apache日志记录客户端请求的域名  http://ask.apelearn.com/question/1037apache 日志切割问题  http://ask.ap

4.16访问日志不记录静态文件,访问日志切割以及静态元素过期时间

访问日志不记录静态文件 一个网站会有很多元素,尤其是图片.js.css等静态文件非常多,每个用户请求一个页面都会访问诸多的图片,这些元素都会被记录在日志中,如果一个网站访问量很大,那么这些日志会增长的非常快,这样不仅会对服务器的磁盘造成影响,更会影响磁盘的读写速度.所以我们要限制这些惊天文件的记录. 具体方法如下:编辑配置文件vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf然后在ErrorLog "logs/111.com-error_l