欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Apache開啟GZIP壓縮功能方法

 更新時間:2018年03月04日 15:43:54   投稿:wdc  
Gzip是一種流行的文件壓縮算法,現(xiàn)在的應(yīng)用十分廣泛,尤其是在Linux平臺,本文講解了如何開啟Apache平臺上的Gzip壓縮功能

Gzip是一種流行的文件壓縮算法,現(xiàn)在的應(yīng)用十分廣泛,尤其是在Linux平臺。Gzip在現(xiàn)代瀏覽器中默認(rèn)都是支持的,當(dāng)一個純文本文件使用Gzip壓縮可以減少70%以上的文件大小,壓縮后可以大大降低了網(wǎng)絡(luò)傳輸?shù)淖止?jié)數(shù),使用Gzip的好處就是可以加快網(wǎng)頁加載的速度,同時是你的網(wǎng)站對搜索引擎更加友好。下面PHP程序員雷雪松詳細的講解下Apache如何使用mod_deflate模塊來實現(xiàn)Gzip壓縮網(wǎng)頁內(nèi)容進行壓縮。

Apache服務(wù)器HTTP請求Gzip處理的過程

1、Apache服務(wù)器接收到瀏覽器的HTTP請求后,檢查瀏覽器是否支持HTTP壓縮(Accept-Encoding 信息)。

2、如果瀏覽器支持HTTP壓縮,Apache服務(wù)器檢查請求文件的后綴名。

a、如果請求文件是HTML、CSS、JS、Images等靜態(tài)文件,Apache服務(wù)器從壓縮緩沖目錄中檢查是否已經(jīng)存在請求文件的最新壓縮文件,如果不存在,返回壓縮的請求文件,并在壓縮緩沖目錄中存放壓縮文件,如果已經(jīng)存在,則直接返回請求文件的壓縮文件。
b、如果請求文件是動態(tài)文件,Web服務(wù)器動態(tài)壓縮內(nèi)容并返回瀏覽器,壓縮內(nèi)容不存放到壓縮緩存目錄中。

Apache支持GZIP壓縮的配置

1、編輯 http.conf 文件,開啟mod_deflate模塊

去掉 #LoadModule headers_module modules/mod_headers.so 前面的注釋#
去掉 #LoadModule deflate_module modules/mod_deflate.so 前面的注釋#
去掉 #LoadModule filter_module modules/mod_filter.so 前面的注釋#

2、配置Gzip壓縮相關(guān)參數(shù)

<IfModule mod_deflate.c>
#壓縮率,6是建議值。
DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/gif image/png image/jpe image/swf image/jpeg image/bmp
#排除不需要壓縮的文件
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI .(?:html|htm)$ no-gzip dont-varySetEnvIfNoCase
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:pdf|doc)$ no-gzip dont-vary
</IfModule>

3、重啟Apache服務(wù)器并且使用瀏覽器請求驗證是否Gzip生效。

相關(guān)文章

最新評論