Apache 靜態緩存配置
阿新 • • 發佈:2018-01-28
mil -- family curl 響應頭 rda close fault 靜態
靜態文件緩存
靜態緩存在客戶端下進行緩存,可以設置緩存文件類型與緩存時間,提升客戶端訪問站點速度。
語法格式
ExpiresByType type/encoding “<base> [plus] <num><type>”
配置靜態緩存
1、模塊解註釋vim /apache2/conf/httpd.conf LoadModule expires_module modules/mod_expires.so
2、主配置文件內編輯,它是一個全局配置。
vim /apache2/conf/httpd.conf <IfModule mod_expires.c> #主配置文件開啟使用expires ExpiresActive on # 指定gif 文件保存1天 image觸發源/類型 ExpiresByType image/gif "access plus 1 days" # 指定jpeg 文件保存24小時 ExpiresByType image/jpeg "access plus 24 hours" # 指定png 文件保存24小時 ExpiresByType image/png "access plus 24 hours" # 指定css 文件保存2小時 ExpiresByType test/css "now plus 2 hour" # 指定javascript 文件保存2小時 ExpiresByType application/x-javascript "now plus 2 hours" # 指定flash 文件保存2小時 ExpiresByType application/x-shockwave-flash "now plus 2 hours" # 處理上述文件 其他都保存0秒(不保存) ExpiresDefault "now plus 0 min" </IfModule>
3、加載配置文件
/usr/local/apache2/bin/apachectl graceful
測試靜態緩存
1、火狐瀏覽器測試
火狐瀏覽器-->F12-->網絡-->304文件-->消息頭-->響應頭-->Cache-Control:max-age=86400(緩存時間)
2、Linux系統下通過curl 測試 加載的是圖片 需要加 -I
curl -x192.168.1.107:80 ‘http://192.168.1.107/static/image/common/logo.png‘ -I
HTTP/1.1 200 OK Date: Tue, 23 Jan 2018 14:44:10 GMT Server: Apache/2.4.27 (Unix) PHP/5.3.22 Last-Modified: Tue, 31 May 2016 03:08:36 GMT ETag: "1149-5341ab0597500" Accept-Ranges: bytes Content-Length: 4425 Cache-Control: max-age=86400 Expires: Wed, 24 Jan 2018 14:44:10 GMT Content-Type: image/png 註:304 調用了本地的緩存文件 註:curl 200 不會顯示 304 註:max-age=86400 緩存時間 註:Expires: Wed, 24 Jan 2018 14:44:10 GMT 過期時間測試結果
Apache 靜態緩存配置