windows下apache開啟gzip壓縮 加快網頁下載速度

來源:互聯網
上載者:User

針對windows版本的apache2.2,開啟方法如下:
第一步:
找到apache的設定檔httpd.conf,找到下面兩行,將前面的 # 去掉. Html代碼 LoadModule deflate_module modules/mod_deflate.so    LoadModule expires_module modules/mod_expires.so  

LoadModule deflate_module modules/mod_deflate.soLoadModule expires_module modules/mod_expires.so


重啟apache伺服器.

第二步:
開啟網站的 .htaccess 檔案,將下面代碼拷貝進去: Html代碼 <IfModule mod_expires.c>   ExpiresActive On    ExpiresDefault "access plus 12 month"    ExpiresByType text/html "access plus 12 months"    ExpiresByType text/css "access plus 12 months"    ExpiresByType image/gif "access plus 12 months"    ExpiresByType image/jpeg "access plus 12 months"    ExpiresByType image/jpg "access plus 12 months"    ExpiresByType image/png "access plus 12 months"    EXpiresByType application/x-shockwave-flash "access plus 12 months"    EXpiresByType application/x-javascript      "access plus 12 months"    ExpiresByType video/x-flv "access plus 12 months"    </IfModule>      <IfModule mod_deflate.c>   SetOutputFilter DEFLATE    AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript    </IfModule>  

<IfModule mod_expires.c>ExpiresActive OnExpiresDefault "access plus 12 month"ExpiresByType text/html "access plus 12 months"ExpiresByType text/css "access plus 12 months"ExpiresByType image/gif "access plus 12 months"ExpiresByType image/jpeg "access plus 12 months"ExpiresByType image/jpg "access plus 12 months"ExpiresByType image/png "access plus 12 months"EXpiresByType application/x-shockwave-flash "access plus 12 months"EXpiresByType application/x-javascript      "access plus 12 months"ExpiresByType video/x-flv "access plus 12 months"</IfModule><IfModule mod_deflate.c>SetOutputFilter DEFLATEAddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript</IfModule>


代碼沒錯,測試通過了的,大家可以放心使用.

解釋一下。ExpiresByType 是通過MIME類型來設定具體檔案的緩衝時間,A表示訪問,A後面的數字表示訪問後的緩衝時間。AddOutputFilterByType表示根據後面的MIME類型來壓縮檔,這裡對css,html,gif,jpeg,png,JavaScript等進行gzip壓縮。更多選項請參考apache手冊哦。

關閉ETag。Etag的問題在於,它是根據可以辨別網站所在的伺服器的具有唯一性的屬性來產生的。當瀏覽器從一台伺服器上獲得頁面內容後到另外一台伺服器上進行驗證時ETag就會不匹配,這種情況對於使用伺服器組和處理請求的網站來說是非常常見的。在設定檔中寫入下面一行即可:

FileETag none

如果是多伺服器負載平衡,可以設定為FileETag MTime Size,apache預設設定為FileETag INode MTime Size,去掉INode。


效果如下:
網址 http://www.k686.com/ 檢測結果如下:
是否壓縮 是
壓縮類型 gzip
原始檔案大小 91844 位元組
壓縮後檔案大小 15365 位元組
壓縮率(估計值) 83.27%


Header資訊
Date Thu, 03 Jun 2010 09:00:14 GMT
Server Apache/2.2.11 (Win32) PHP/5.2.10
X-Powered-By PHP/5.2.10
Set-Cookie PHPSESSID=nkcqphhqt8005prgnn35fdfif4; path=/
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control private
Pragma no-cache
Vary Accept-Encoding
Content-Encoding gzip
Content-Length 15365
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type text/html; charset=utf-8

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.