您好,登錄后才能下訂單哦!
如何進行Apache服務mod_deflate模塊分析,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
LAMP架構應用實戰—Apache服務
mod_deflate壓縮模塊
今天來介紹下比較常用的模塊mod_deflate壓縮模塊
一:mod_deflate模塊介紹
mod_deflate壓縮模塊提供了DEFLATE輸出過濾器,允許服務器將內容發送給客戶端之前進行壓縮,節省帶寬資源
二:mod_deflate模塊查看
直接編譯安裝查看如下
[root@Centos modules]# /application/apache/bin/apachectl -l|grep mod_deflate
mod_deflate.c
以DSO方式編譯安裝查看如下
[root@Centos modules]# ls -l|grep defla
-rwxr-xr-x. 1 root root 86591 Sep 18 15:26 mod_deflate.so
但是以上兩種方式不能同時安裝,否則會出現錯誤
[root@Centos conf]# /application/apache/bin/apachectl -M|grep deflate
deflate_module (shared)
查看幫助
[root@Centos httpd-2.4.23]# ./configure --help|grep deflate
--enable-deflate Deflate transfer encoding support
編譯、或以DSO安裝方式安裝與前面的緩存模塊安裝相同,這里就不再介紹了
三:mod_deflate配置
配置前看下HTTP頭的信息
[root@Centos modules]# curl -I http://blog.abc.com:9999/
HTTP/1.1 200 OK
Date: Sun, 18 Sep 2016 07:37:58 GMT
Server: Apache/2.4.23 (Unix)
Last-Modified: Fri, 09 Sep 2016 12:19:55 GMT
ETag: "1f-53c122a061992"
Accept-Ranges: bytes
Content-Length: 31
Cache-Control: max-age=31104000
Expires: Wed, 13 Sep 2017 07:37:58 GMT
Content-Type: text/html
備份并配置模塊
[root@Centos conf]# cp httpd.conf httpd.conf.0918
[root@Centos conf]# vi httpd.conf
中間內容省略
<IfModule mod_deflate.c>
DeflateCompressionLevel 9
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain /text/xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/css
</IfModule>
"httpd.conf" 521L, 18903C written
語法檢查與服務重啟
[root@Centos conf]# /application/apache/bin/apachectl -t
Syntax OK
[root@Centos conf]# /application/apache/bin/apachectl graceful
[root@Centos conf]# lsof -i tcp:9999
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 2156 root 8u IPv6 16255 0t0 TCP *:distinct (LISTEN)
httpd 13911 daemon 8u IPv6 16255 0t0 TCP *:distinct (LISTEN)
httpd 13912 daemon 8u IPv6 16255 0t0 TCP *:distinct (LISTEN)
httpd 13913 daemon 8u IPv6 16255 0t0 TCP *:distinct (LISTEN)
[root@Centos conf]# ps -ef|grep http
root 2156 10 15:13 ? 00:00:00 /application/apache2.4.23/bin/httpd -k restart
daemon13911 2156 0 15:49 00:00:00 /application/apache2.4.23/bin/httpd -k restart
daemon 13912 2156 0 15:49 00:00:00 /application/apache2.4.23/bin/httpd -k restart
daemon 13913 2156 0 15:49 ?00:00:00 /application/apache2.4.23/bin/httpd -k restart
root 14003 1941 015:50 pts/0 00:00:00 grep http
測試配置內容
[root@Centos conf]# curl -I http://blog.abc.com:9999/deflate.html
HTTP/1.1 200 OK
Date: Sun, 18 Sep 2016 09:32:39 GMT
Server: Apache/2.4.23 (Unix)
Last-Modified: Sun, 18 Sep 2016 08:10:40 GMT
ETag: "309-53cc3bb2de520"
Accept-Ranges: bytes
Content-Length: 777
Vary: Accept-Encoding 出現這個提示表明已啟用壓縮
Cache-Control: max-age=31104000
Expires: Wed, 13 Sep 2017 09:32:39 GMT
Content-Type: text/html
把之前的配置內容注釋掉
[root@Centos conf]# /application/apache/bin/apachectl -t
Syntax OK
[root@Centos conf]# /application/apache/bin/apachectl graceful
[root@Centos conf]# ps -ef |grep http
root 14492 1 0 17:03 ? 00:00:00 /application/apache2.4.23/bin/httpd -k restart
daemon 14998 14492 0 17:39 ? 00:00:00 /application/apache2.4.23/bin/httpd -k restart
daemon 14999 14492 0 17:39 ? 00:00:00 /application/apache2.4.23/bin/httpd -k restart
daemon 15000 14492 0 17:39 ?00:00:00 /application/apache2.4.23/bin/httpd -k restart
root 15083 148 0 17:39 pts/0 00:00:00 grep http
[root@Centos conf]# lsof -i tcp:9999
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 14492 root 8u IPv6 28964 0t0 TCP *:distinct (LISTEN)
httpd 14998 daemon 8u IPv6 28964 0t0 TCP *:distinct (LISTEN)
httpd 14999 daemon 8u IPv6 28964 0t0 TCP *:distinct (LISTEN)
httpd 15000 daemon 8u IPv6 28964 0t0 TCP *:distinct (LISTEN)
[root@Centos conf]# curl -I http://blog.abc.com:9999/deflate.html
HTTP/1.1 200 OK
Date: Sun, 18 Sep 2016 09:40:08 GMT
Server: Apache/2.4.23 (Unix)
Last-Modified: Sun, 18 Sep 2016 08:10:40 GMT
ETag: "309-53cc3bb2de520"
Accept-Ranges: bytes
Content-Length: 777
Cache-Control: max-age=31104000
Expires: Wed, 13 Sep 2017 09:40:08 GMT
Content-Type: text/html
發現沒有配置的時候是不會出現相關提示內容
提示:如果編譯安裝后,主配置文件中沒有加入deflate此模塊,那么我們可以手要增加一個這樣的模塊
LoadModule deflate_module modules/mod_deflate.so
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。