11.22 訪問日誌不記錄靜態文件
- 網站大多元素爲靜態文件,如圖片、css、js等,這些元素能夠不用記錄
- 把虛擬主機配置文件改爲以下:在custom上邊進行配置
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
ServerAlias 123.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/123.com-access_log" combined env=!img
</VirtualHost>
- 從新加載配置文件 -t, graceful
11.23 訪問日誌切割
- 日誌一直記錄總有一天會把整個磁盤佔滿,因此有必要讓它自動切割,並刪除老的日誌文件
- 把虛擬主機配置文件改爲以下:
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
ServerAlias 123.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/123.com-access_%Y%m%d.log 86400" combined env=!img
</VirtualHost>
- rotatelogs爲一個工具,apache自帶的一個日誌切割工具,-l表明時區CST,%Y%m%d表示年月日,86400秒即爲一天
- 從新加載配置文件 -t, graceful
- ls /usr/local/apache2.4/logs
11.24 靜態元素過時時間
- 瀏覽器訪問網站的圖片時會把靜態的文件緩存在本地電腦裏,這樣下次再訪問時就不用去遠程下載了
- 增長配置
<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>
- 須要expires_module模塊,在配置文件中打開此模塊
擴展
- apache日誌記錄代理IP以及真實客戶端IP http://www.lishiming.net/thread-960-1-1.html
- apache只記錄指定URI的日誌 http://www.lishiming.net/thread-981-1-1.html
- apache日誌記錄客戶端請求的域名 http://www.lishiming.net/thread-1037-1-1.html
- apache 日誌切割問題 http://www.lishiming.net/thread-566-1-1.html