Apache網頁壓縮

來源:互聯網
上載者:User

標籤:img   logs   目的   查看   壓力   modules   頭部   演算法   src   

壓縮功能概述
      配置 Apache 的網頁壓縮功能,是使用 Gzip 壓縮演算法來對 Apache 伺服器發布的網頁內容進行壓縮後再傳輸到用戶端瀏覽器。

網頁壓縮的優勢
     加快網頁載入的速度,改善使用者的瀏覽體驗
     降低網路傳輸頻寬,伺服器節省流量
     網頁壓縮有利於搜尋引擎的抓取

網頁壓縮模組分類
       Apache 能實現網頁壓縮功能的模組有 mod_gzip 模組和 mod_deflate 模組。Apache1.x 系列沒有內建的網頁壓縮技術,但可以使用額外的第三方 mod_gzip 模組來執行壓縮。Apache 2.x 系列官方在發布的時候,就把網頁壓縮功能考慮進去,內建了 mod_deflate 這個模組,用於取代 mod_gzip 模組


啟用網頁壓縮功能

 [[email protected] ~]# apachectl -D DUMP_MODULES

Loaded Modules:
core_module (static)
authn_file_module (static)
authn_default_module (static)
authz_host_module (static)
authz_groupfile_module (static)
authz_user_module (static)
authz_default_module (static)
auth_basic_module (static)

……
Syntax OK
[[email protected] ~]# apachectl -t -D DUMP_MODULES | grep deflate //-t 選項可不加
Syntax OK
[[email protected] ~]# apachectl -D DUMP_MODULES | grep deflate
Syntax OK

發現未安裝 deflate_module (static),重新編譯安裝

[[email protected] ~]# service httpd stop

[[email protected] ~]# cd /usr/src/httpd-2.2.31/

[[email protected] httpd-2.2.31]# ./configure --prefix=/usr/local/httpd/ --enable-so --enable-
rewrite --enable-charset-lite --enable-cgi --enable-deflate && make && make install

[[email protected] ~]# apachectl -D DUMP_MODULES | grep deflate
deflate_module (static)
Syntax OK

[[email protected] ~]# service httpd start

為了方便對比,在啟用模組前,先使用 fiddler 工具抓包

 

配置網頁的緩衝時間

配置網頁緩衝時間概述 

       通過 mod_expires 模組配置 Apache,使網頁能在用戶端瀏覽器緩衝一段時間,以避免重複請求,減輕服務端工作壓力。

       啟用 mod_expires 模組後,會自動產生頁面頭部資訊中的 Expires 標籤和 Cache-Control 標籤,從而降低用戶端的訪問頻率和次數,達到減少不必要的流量和增加訪問速度的目的。

 

啟用網頁緩衝功能

查看是否安裝了 mod_expires 模組 

[[email protected] ~]# apachectl -D DUMP_MODULES | grep expires
Syntax OK

發現未安裝 expires_module (static),重新編譯安裝

[[email protected] ~]# service httpd stop

[[email protected] ~]# cd /usr/src/httpd-2.2.31/

[[email protected] httpd-2.2.31]# ./configure --prefix=/usr/local/httpd
/ --enable-so --enable-rewrite --enable-charset-lite --enable-cgi --enable-deflate --enable-
expires && make && make install

[[email protected] ~]# apachectl -D DUMP_MODULES | grep expires
expires_module (static)
Syntax OK

[[email protected] ~]# service httpd start

為了方便對比,在啟用模組前,先使用 fiddler 工具抓包

 

修改設定檔啟用緩衝功能
在 httpd.conf 主設定檔最後加上如下內容

[[email protected] ~]# vim /usr/local/httpd/conf/httpd.conf

423 <IfModule mod_expires.c>
424 ExpiresActive On                                  // 開啟網頁緩衝功能
425 ExpiresDefault "access plus 60 seconds" //http 協議下任的文檔都是 60 秒之後到期
426 </IfModule>

 

Apache網頁壓縮

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.