天天看點

使用mod_deflate子產品壓縮頁面優化傳輸速度

在HTTPD主配置檔案中添加如下,并確定deflate子產品是啟用的

#vim /etc/httpd/conf/httpd.conf

       SetOutputFilter DEFLATE//調用一個叫DEFLATE輸出過濾器

       # mod_deflate configuration

       # Restrict compression to these MIME types

       AddOutputFilterByType DEFLATE text/plain

       AddOutputFilterByType DEFLATE text/html

       AddOutputFilterByType DEFLATE application/xhtml+xml

       AddOutputFilterByType DEFLATE text/xml

       AddOutputFilterByType DEFLATE application/xml

       AddOutputFilterByType DEFLATE application/x-javascript

       AddOutputFilterByType DEFLATE text/javascript

       AddOutputFilterByType DEFLATE text/css

       # Level of compression (Highest 9 - Lowest 1)

       DeflateCompressionLevel 9//過濾時壓縮比

       # Netscape 4.x has some problems.

       BrowserMatch ^Mozilla/4 gzip-only-text/html

       # Netscape 4.06-4.08 have some more problems

       BrowserMatch ^Mozilla/4\.0[678] no-gzip

       # MSIE masquerades as Netscape, but it is fine

       BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

然後#service httpd reload

#cp /etc/rc.d/rc.sysinit /vhosts/web1/htdocs/test.html     //vhosts/web1/htdocs這個目錄是提前建立的

#curl -I http://192.160.108.160/test.html  //檢視響應封包的首部

使用mod_deflate子產品壓縮頁面優化傳輸速度

#curl -I --compressed http://192.160.108.160/test.html

使用mod_deflate子產品壓縮頁面優化傳輸速度

可以看出調用的壓縮功能以後,響應封包首部的内容長度是原來的三分之一

轉載于:https://www.cnblogs.com/hanshanxiaoheshang/p/9139431.html