訪問日誌不記錄靜態文件、切割和靜態元素過時時間
11月16日任務javascript
11.22 訪問日誌不記錄靜態文件css
11.23 訪問日誌切割java
11.24 靜態元素過時時間apache
1. 訪問日誌不記錄靜態文件瀏覽器

示例一:緩存
- 網站大多元素爲靜態文件,如圖片、css、js等,這些元素能夠不用記錄
- 把虛擬主機配置文件改爲以下:
- <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
- 測試:
- mkdir /data/wwwroot/www.123.com/images //建立目錄,並在這目錄下上傳一個圖片
- curl -x127.0.0.1:80 -I 123.com/images/123.jpg
- tail /usr/local/apache2.4/logs/123.com-access_log
實驗:一app

- 從新加載配置文件 -t, graceful
- 測試:
- mkdir /data/wwwroot/www.123.com/images //建立目錄,並在這目錄下上傳一個圖片
- curl -x127.0.0.1:80 -I 123.com/images/123.jpg
- tail /usr/local/apache2.4/logs/123.com-access_log 查看是否有記錄日誌
2.訪問日誌切割curl

- 日誌一直記錄總有一天會把整個磁盤佔滿,因此有必要讓它自動切割,並刪除老的日誌文件
- 把虛擬主機配置文件改爲以下:
- <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>
- 從新加載配置文件 -t, graceful
- ls /usr/local/apache2.4/logs
實驗一:日誌切割測試




- 能夠作個任務計劃,crond ,將超過一個月的日誌刪除或者備份到其餘地方,再刪除。
3.靜態元素過時時間網站

- 瀏覽器訪問網站的圖片時會把靜態的文件緩存在本地電腦裏,這樣下次再訪問時就不用去遠程下載了
- 增長配置
- <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
- curl測試,看cache-control: max-age
實驗一:

- 編輯住配置文件,查找expire,刪除#號,開啓該模塊




歡迎關注本站公眾號,獲取更多信息