apache配置優化(七)

Apache--mod_deflate模塊(這是apache調優的重要參數)javascript

mod_deflate介紹:css

該模提供了DEFLATE輸出過濾器,容許服務器在將輸出內容發發送到客戶端之前進行壓縮,以節約帶寬。html

好處一:提高用戶體驗java

因爲內容小了,因此訪問頁面就快了,用戶體驗提高了,網站口碑就行了。apache

好處二:節省網站帶寬成本瀏覽器

因爲數據壓縮傳輸,所以節省了網站的帶寬流量成本,會多消耗一些CPU來進行壓縮,知足用戶了,公司也少花錢了。服務器


檢查模塊是否安裝:app

[root@eric6 ~]#/application/apache/bin/apachectl -l|grep mod_deflateide

mod_deflate.c>>出現這代表已在安裝時加入了支持測試

若是在查找的時候沒有安裝該模塊,能夠使用DSO方式安裝:

[root@eric6metadata]# cd /home/tools/httpd-2.2.25/modules/metadata/

[root@eric6metadata]# ll mod_deflate.c

-rw-r--r-- 1liuyalei liuyalei 18285 11月 12 2008 mod_deflate.c

[root@eric6metadata]# /application/apache/bin/apxs -c -i -a mod_deflate.c

註釋expires配置

<ifmodulemod_deflate.c>

DeflateCompressionLevel 9#壓縮等級,越大效率越高,耗CPU/MEM也高

SetOutputFilter DEFLATE#啓用壓縮

AddOutputFilterByType DEFLATEtext/html text/plain text/xml#壓縮類型

AddOutputFilterByType DEFLATEapplication/javascript#壓縮類型

AddOutputFilterByType DEFLATE text/css#壓縮類型

</ifmodule>



實例:爲一個server標籤添加expires功能

<VirtualHost*:80>

ServerAdmin 952773925@qq.com

DocumentRoot "/var/bbs"

ServerName bbs.liuyalei.com

ServerAlias liuyalei.com

ErrorLog "logs/bbs-error_log"

CustomLog "logs/bbs-access_log"common

ExpiresActive on

ExpiresDefault "access plus 12month"

ExpiresByType text/html "accessplus 12 months"

ExpiresByType text/css "accessplus 12 months"

ExpiresByType p_w_picpath/gif "accessplus 12 months"

ExpiresByType p_w_picpath/jpeg "accessplus 12 months"

ExpiresByType p_w_picpath/jpg "accessplus 12 months"

ExpiresByType p_w_picpath/png "accessplus 12 months"

EXpiresByType application/x-shockwave-flash"access plus 12 months"

EXpiresByType application/x-javascript"access plus 12 months"

ExpiresByType video/x-flv "accessplus 12 months"


<ifmodulemod_deflate.c>

DeflateCompressionLevel 9

SetOutputFilter DEFLATE

AddOutputFilterByType DEFLATEtext/html text/plain text/xml

AddOutputFilterByType DEFLATEapplication/javascript

AddOutputFilterByType DEFLATE text/css

</ifmodule>


</VirtualHost>



檢查配置,重啓apache服務

[root@eric6apache]# bin/apachectl -t

Syntax OK

[root@eric6apache]# bin/apachectl graceful

[root@eric6apache]# lsof -i:80

COMMANDPIDUSERFDTYPE DEVICE SIZE/OFF NODE NAME

httpd4734root4uIPv6 1635410t0TCP *:http (LISTEN)

httpd8470 daemon4uIPv6 1635410t0TCP *:http (LISTEN)

httpd8471 daemon4uIPv6 1635410t0TCP *:http (LISTEN)

httpd8472 daemon4uIPv6 1635410t0TCP *:http (LISTEN)




在火狐瀏覽器測試:

具體按照插件見以前文檔

相關文章
相關標籤/搜索