如何进行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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。