171221---LAMP Apache访问日志
访问日志不记录指定类型的文件
- 网站大多元素为静态文件,如图片,css,js等,这些元素可以不用记录
- 把虚拟主机配置文件改成如下: <VirtualHost :80> DocumentRoot "/data/wwwroot/www.111.com ServerName www.111.com ServerAlias 111.com 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>
- 重新加载配置文件-t,graceful
- mkdir /data/wwwroot/www.111.com/images #创建目录,并在这目录下上传一个图片
- curl -x 127.0.0.1:80 -I 111.com/images/111.jpg
- tail /usr/local/apache2.4/logs/111.com_access_log
[[email protected] ~]# vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
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>
[[email protected] ~]# curl -x127.0.0.1:80 111.com/alskdh.jpg -I
HTTP/1.1 404 Not Found
Date: Fri, 22 Dec 2017 01:17:43 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Content-Type: text/html; charset=iso-8859-1
[[email protected] ~]# tail /usr/local/apache2.4/logs/111.com-access_log
192.168.25.1 - aa [21/Dec/2017:13:15:41 +0800] "GET /123.php HTTP/1.1" 200 7
127.0.0.1 - - [21/Dec/2017:13:25:10 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:27 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:43 +0800] "HEAD HTTP://2111.com.cn/ HTTP/1.1" 301 -
192.168.25.35 - - [21/Dec/2017:13:26:00 +0800] "GET HTTP://2111.com.cn/ HTTP/1.1" 301 223
192.168.25.1 - aa [21/Dec/2017:13:40:58 +0800] "GET /123.php HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:41:41 +0800] "HEAD http://111.com/123.com HTTP/1.1" 404 -
192.168.25.35 - - [21/Dec/2017:13:42:11 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 -
192.168.25.35 - - [21/Dec/2017:13:42:32 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0"
127.0.0.1 - - [22/Dec/2017:09:17:43 +0800] "HEAD HTTP://111.com/alskdh.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
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>
[[email protected] ~]# curl -x127.0.0.1:80 111.com/alskdh.jpg -I
HTTP/1.1 404 Not Found
Date: Fri, 22 Dec 2017 01:17:43 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Content-Type: text/html; charset=iso-8859-1
[[email protected] ~]# tail /usr/local/apache2.4/logs/111.com-access_log
192.168.25.1 - aa [21/Dec/2017:13:15:41 +0800] "GET /123.php HTTP/1.1" 200 7
127.0.0.1 - - [21/Dec/2017:13:25:10 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:27 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:43 +0800] "HEAD HTTP://2111.com.cn/ HTTP/1.1" 301 -
192.168.25.35 - - [21/Dec/2017:13:26:00 +0800] "GET HTTP://2111.com.cn/ HTTP/1.1" 301 223
192.168.25.1 - aa [21/Dec/2017:13:40:58 +0800] "GET /123.php HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:41:41 +0800] "HEAD http://111.com/123.com HTTP/1.1" 404 -
192.168.25.35 - - [21/Dec/2017:13:42:11 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 -
192.168.25.35 - - [21/Dec/2017:13:42:32 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0"
127.0.0.1 - - [22/Dec/2017:09:17:43 +0800] "HEAD HTTP://111.com/alskdh.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful
[[email protected] ~]# curl -x127.0.0.1:80 111.com/alskdh.jpg -I
HTTP/1.1 404 Not Found
Date: Fri, 22 Dec 2017 01:21:34 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Content-Type: text/html; charset=iso-8859-1
[[email protected] ~]# tail /usr/local/apache2.4/logs/111.com-access_log
192.168.25.1 - aa [21/Dec/2017:13:15:41 +0800] "GET /123.php HTTP/1.1" 200 7
127.0.0.1 - - [21/Dec/2017:13:25:10 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:27 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:43 +0800] "HEAD HTTP://2111.com.cn/ HTTP/1.1" 301 -
192.168.25.35 - - [21/Dec/2017:13:26:00 +0800] "GET HTTP://2111.com.cn/ HTTP/1.1" 301 223
192.168.25.1 - aa [21/Dec/2017:13:40:58 +0800] "GET /123.php HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:41:41 +0800] "HEAD http://111.com/123.com HTTP/1.1" 404 -
192.168.25.35 - - [21/Dec/2017:13:42:11 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 -
192.168.25.35 - - [21/Dec/2017:13:42:32 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0"
127.0.0.1 - - [22/Dec/2017:09:17:43 +0800] "HEAD HTTP://111.com/alskdh.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
Syntax OK
[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful
[[email protected] ~]# curl -x127.0.0.1:80 111.com/alskdh.jpg -I
HTTP/1.1 404 Not Found
Date: Fri, 22 Dec 2017 01:21:34 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Content-Type: text/html; charset=iso-8859-1
[[email protected] ~]# tail /usr/local/apache2.4/logs/111.com-access_log
192.168.25.1 - aa [21/Dec/2017:13:15:41 +0800] "GET /123.php HTTP/1.1" 200 7
127.0.0.1 - - [21/Dec/2017:13:25:10 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:27 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:43 +0800] "HEAD HTTP://2111.com.cn/ HTTP/1.1" 301 -
192.168.25.35 - - [21/Dec/2017:13:26:00 +0800] "GET HTTP://2111.com.cn/ HTTP/1.1" 301 223
192.168.25.1 - aa [21/Dec/2017:13:40:58 +0800] "GET /123.php HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:41:41 +0800] "HEAD http://111.com/123.com HTTP/1.1" 404 -
192.168.25.35 - - [21/Dec/2017:13:42:11 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 -
192.168.25.35 - - [21/Dec/2017:13:42:32 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0"
127.0.0.1 - - [22/Dec/2017:09:17:43 +0800] "HEAD HTTP://111.com/alskdh.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
[[email protected] ~]# cd /data/wwwroot/111.com/
[[email protected] 111.com]# ls
123.php index.php
[[email protected] 111.com]# rz
上传一张图片
[[email protected] 111.com]# ls
123.php index.php
[[email protected] 111.com]# rz
上传一张图片
[[email protected] 111.com]# ls
123.php baidu.png index.php
[[email protected] 111.com]# curl -x127.0.0.1:80 111.com/baidu.png -I
HTTP/1.1 200 OK
Date: Fri, 22 Dec 2017 01:29:19 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Last-Modified: Fri, 22 Dec 2017 01:24:30 GMT
ETag: "1501e-560e3ad9acf80"
Accept-Ranges: bytes
Content-Length: 86046
Content-Type: image/png
123.php baidu.png index.php
[[email protected] 111.com]# curl -x127.0.0.1:80 111.com/baidu.png -I
HTTP/1.1 200 OK
Date: Fri, 22 Dec 2017 01:29:19 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Last-Modified: Fri, 22 Dec 2017 01:24:30 GMT
ETag: "1501e-560e3ad9acf80"
Accept-Ranges: bytes
Content-Length: 86046
Content-Type: image/png
Windows下访问浏览器
[[email protected] 111.com]# tail /usr/local/apache2.4/logs/111.com-access_log
127.0.0.1 - - [21/Dec/2017:13:25:10 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:27 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:43 +0800] "HEAD HTTP://2111.com.cn/ HTTP/1.1" 301 -
192.168.25.35 - - [21/Dec/2017:13:26:00 +0800] "GET HTTP://2111.com.cn/ HTTP/1.1" 301 223
192.168.25.1 - aa [21/Dec/2017:13:40:58 +0800] "GET /123.php HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:41:41 +0800] "HEAD http://111.com/123.com HTTP/1.1" 404 -
192.168.25.35 - - [21/Dec/2017:13:42:11 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 -
192.168.25.35 - - [21/Dec/2017:13:42:32 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0"
127.0.0.1 - - [22/Dec/2017:09:17:43 +0800] "HEAD HTTP://111.com/alskdh.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
192.168.25.1 - - [22/Dec/2017:09:30:43 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "http://111.com/baidu.png" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36"
127.0.0.1 - - [21/Dec/2017:13:25:10 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:27 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:43 +0800] "HEAD HTTP://2111.com.cn/ HTTP/1.1" 301 -
192.168.25.35 - - [21/Dec/2017:13:26:00 +0800] "GET HTTP://2111.com.cn/ HTTP/1.1" 301 223
192.168.25.1 - aa [21/Dec/2017:13:40:58 +0800] "GET /123.php HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:41:41 +0800] "HEAD http://111.com/123.com HTTP/1.1" 404 -
192.168.25.35 - - [21/Dec/2017:13:42:11 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 -
192.168.25.35 - - [21/Dec/2017:13:42:32 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0"
127.0.0.1 - - [22/Dec/2017:09:17:43 +0800] "HEAD HTTP://111.com/alskdh.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
192.168.25.1 - - [22/Dec/2017:09:30:43 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "http://111.com/baidu.png" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36"
去掉env=!img 重新加载访问
[[email protected] 111.com]# tail /usr/local/apache2.4/logs/111.com-access_log
192.168.25.35 - - [21/Dec/2017:13:25:27 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:43 +0800] "HEAD HTTP://2111.com.cn/ HTTP/1.1" 301 -
192.168.25.35 - - [21/Dec/2017:13:26:00 +0800] "GET HTTP://2111.com.cn/ HTTP/1.1" 301 223
192.168.25.1 - aa [21/Dec/2017:13:40:58 +0800] "GET /123.php HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:41:41 +0800] "HEAD http://111.com/123.com HTTP/1.1" 404 -
192.168.25.35 - - [21/Dec/2017:13:42:11 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 -
192.168.25.35 - - [21/Dec/2017:13:42:32 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0"
127.0.0.1 - - [22/Dec/2017:09:17:43 +0800] "HEAD HTTP://111.com/alskdh.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
192.168.25.1 - - [22/Dec/2017:09:30:43 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "http://111.com/baidu.png" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36"
127.0.0.1 - - [22/Dec/2017:09:35:34 +0800] "HEAD HTTP://111.com/baidu.png HTTP/1.1" 200 - "-" "curl/7.29.0"
192.168.25.35 - - [21/Dec/2017:13:25:27 +0800] "GET HTTP://111.com/ HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:25:43 +0800] "HEAD HTTP://2111.com.cn/ HTTP/1.1" 301 -
192.168.25.35 - - [21/Dec/2017:13:26:00 +0800] "GET HTTP://2111.com.cn/ HTTP/1.1" 301 223
192.168.25.1 - aa [21/Dec/2017:13:40:58 +0800] "GET /123.php HTTP/1.1" 200 7
192.168.25.35 - - [21/Dec/2017:13:41:41 +0800] "HEAD http://111.com/123.com HTTP/1.1" 404 -
192.168.25.35 - - [21/Dec/2017:13:42:11 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 -
192.168.25.35 - - [21/Dec/2017:13:42:32 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0"
127.0.0.1 - - [22/Dec/2017:09:17:43 +0800] "HEAD HTTP://111.com/alskdh.jpg HTTP/1.1" 404 - "-" "curl/7.29.0"
192.168.25.1 - - [22/Dec/2017:09:30:43 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "http://111.com/baidu.png" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36"
127.0.0.1 - - [22/Dec/2017:09:35:34 +0800] "HEAD HTTP://111.com/baidu.png HTTP/1.1" 200 - "-" "curl/7.29.0"
访问日志切割
- 日志一直记录总有一天会把整个磁盘占满,所以有必要设置自动切割,并删除旧的日志文件
- 把虚拟主机配置文件改成如下: <VirtualHost :80> DocumentRoot "/data/wwwroot/www.111.com" ServerName www.111.com ServerAlias 111.com 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 "|/usr/local/apache2.4/bin/rotatelogs -l logs/111.com-access_%Y%m%d.log 86400" combined env=!img </VirtualHost>
- 重新加载配置文件-t,graceful
- ls /usr/local/apache2.4/logs
[[email protected] 111.com]# vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
SetEnvIf Request_URI ".*\.gif$" img
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 "|/usr/local/apache2.4/bin/rotatelogs -l logs/111.com-access_%Y%m%d.log 86400" combined env=!img
</VirtualHost>
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 "|/usr/local/apache2.4/bin/rotatelogs -l logs/111.com-access_%Y%m%d.log 86400" combined env=!img
</VirtualHost>
[[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
111.com-access_log abc.com-access_log access_log httpd.pid
111.com-error_log abc.com-error_log error_log
配置静态元素过期时间
- 浏览器访问网站的图片时会把静态的文件缓存在本地电脑里,这样下次再访问时就不用去远程下载
- 增加配置 <IfMondule 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" ExpiresByType "now plus 0 min" </IfModule>
- 需要expires module
- curl测试,看cache-control:max-age
<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>
[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl -M |grep expire
[[email protected] 111.com]# vi /usr/local/apache2.4/conf/httpd.conf /////将expires模块打开
[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl -M |grep expire
expires_module (shared)
[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl graceful
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>
[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl -M |grep expire
[[email protected] 111.com]# vi /usr/local/apache2.4/conf/httpd.conf /////将expires模块打开
[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl -M |grep expire
expires_module (shared)
[[email protected] 111.com]# /usr/local/apache2.4/bin/apachectl graceful
[[email protected] 111.com]# curl -x127.0.0.1:80 111.com/qq.png -I
HTTP/1.1 200 OK
Date: Fri, 22 Dec 2017 02:11:59 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Last-Modified: Fri, 22 Dec 2017 01:24:30 GMT
ETag: "1501e-560e3ad9acf80"
Accept-Ranges: bytes
Content-Length: 86046
Cache-Control: max-age=86400
Expires: Sat, 23 Dec 2017 02:11:59 GMT
Content-Type: image/png
HTTP/1.1 200 OK
Date: Fri, 22 Dec 2017 02:11:59 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Last-Modified: Fri, 22 Dec 2017 01:24:30 GMT
ETag: "1501e-560e3ad9acf80"
Accept-Ranges: bytes
Content-Length: 86046
Cache-Control: max-age=86400
Expires: Sat, 23 Dec 2017 02:11:59 GMT
Content-Type: image/png