溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何進行Apache服務(wù)mod_deflate模塊分析

發(fā)布時間:2022-01-05 18:32:39 來源:億速云 閱讀:155 作者:柒染 欄目:云計算

如何進行Apache服務(wù)mod_deflate模塊分析,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。

LAMP架構(gòu)應(yīng)用實戰(zhàn)—Apache服務(wù)

mod_deflate壓縮模塊

今天來介紹下比較常用的模塊mod_deflate壓縮模塊

一:mod_deflate模塊介紹

mod_deflate壓縮模塊提供了DEFLATE輸出過濾器,允許服務(wù)器將內(nèi)容發(fā)送給客戶端之前進行壓縮,節(jié)省帶寬資源

二: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

但是以上兩種方式不能同時安裝,否則會出現(xiàn)錯誤

[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 

中間內(nèi)容省略

<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

語法檢查與服務(wù)重啟

[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

測試配置內(nèi)容

[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      出現(xiàn)這個提示表明已啟用壓縮

Cache-Control: max-age=31104000

Expires: Wed, 13 Sep 2017 09:32:39 GMT

Content-Type: text/html

把之前的配置內(nèi)容注釋掉

[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

發(fā)現(xiàn)沒有配置的時候是不會出現(xiàn)相關(guān)提示內(nèi)容

提示:如果編譯安裝后,主配置文件中沒有加入deflate此模塊,那么我們可以手要增加一個這樣的模塊

LoadModule deflate_module modules/mod_deflate.so

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI