官方说明:Compress content before it is delivered to the client
检查是否安装模块:
0 1 2 3 4 |
[root@lamp stat]# /usr/local/apache/bin/apachectl -l |grep deflate [root@lamp stat]# /usr/local/apache/bin/apachectl -M |grep deflate deflate_module (shared) [root@lamp stat]# grep deflate /usr/local/apache/conf/httpd.conf LoadModule deflate_module modules/mod_deflate.so |
安装mod_deflate模块:
0 1 2 3 4 5 6 7 8 9 |
[root@lamp filters]# pwd #此目录是apache的解压包目录 /byrd/tools/httpd-2.4.9/modules/filters/mod_deflate.c [root@lamp metadata]# /usr/local/apache/bin/apxs -c -i -a mod_deflate.c #/usr/local/apache/是apache安装目录,此处以dso方式进行编译安装。完成后请检查配置 chmod 755 /byrd/tools/httpd-2.4.9/modules/filters/mod_deflate.c [activating module `expires' in /byrd/server/httpd-2.4.9/conf/httpd.conf] apxs命令参数说明: -i 此选项表示需要执行安装操作,以安装一个或多个动态共享对象到服务器的modules目录中。 -a 此选项自动增加一个LoadModule行到httpd.conf文件中,以激活此模块,或者,如果此行已经存在,则启用之。 -A 与 -a 选项类似,但是它增加的LoadModule命令有一个井号前缀(#),即此模块已经准备就绪但尚未启用。 -c 此选项表示需要执行编译操作。它首先会编译C源程序(.c)files为对应的目标代码文件(.o),然后连接这些目标代码和files中其余的目标代码文件(.o和.a),以生成动态共享对象dsofile 。如果没有指定 -o 选项,则此输出文件名由files中的第一个文件名推测得到,也就是默认为mod_name.so 。 |
未配置mod_deflate:
0 1 2 3 4 5 6 7 8 |
[root@lamp conf]# curl -I 192.168.199.178/static/js/common.js HTTP/1.1 200 OK Date: Sun, 11 May 2014 14:06:12 GMT Server: Apache/2.4.9 (Unix) PHP/5.5.11 Last-Modified: Fri, 28 Feb 2014 06:52:18 GMT ETag: "10fe6-4f371e0f74c80" Accept-Ranges: bytes Content-Length: 69606 Content-Type: application/javascript |
编辑httpd.conf增加:
0 1 2 3 4 5 6 7 8 |
<ifmodule mod_deflate.c> DeflateCompressionLevel 9 SetOutputFilter DEFLATE AddOutputFilterByType DEFLATE text/html text/plain text/xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE text/css SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary </ifmodule> |
配置mod_deflate后:
0 1 2 3 4 5 6 7 8 9 |
[root@lamp conf]# curl -I 192.168.199.178/static/js/common.js HTTP/1.1 200 OK Date: Sun, 11 May 2014 14:06:52 GMT Server: Apache/2.4.9 (Unix) PHP/5.5.11 Last-Modified: Fri, 28 Feb 2014 06:52:18 GMT ETag: "10fe6-4f371e0f74c80" Accept-Ranges: bytes Content-Length: 69606 Vary: Accept-Encoding Content-Type: application/javascript |
疑难杂症:
0 1 2 3 4 5 6 7 8 9 10 |
Q:httpd: Syntax error on line 103 of /byrd/server/httpd-2.4.9/conf/httpd.conf: Cannot load modules/mod_deflate.so into server: /byrd/server/httpd-2.4.9/modules/mod_deflate.so: undefined symbol: inflateEnd A:办法1.需要在 LoadModule deflate_module modules/mod_deflate.so 的前面加载zlib.so 如32操作系统增加以下内容: LoadFile /usr/lib/libz.so LoadModule deflate_module modules/mod_deflate.so 如64操作系统增加以下内容: LoadFile /usr/lib64/libz.so LoadModule deflate_module modules/mod_deflate.so 办法2:vi /usr/local/apache2/bin/apr-config 修改LDFLAGS=" " 为 LDFLAGS="-lz" 然后再apxs -ica mod_deflate.c |
申明:本文由BYRD原创(基于Centos6.4 X64、PHP5.5.11、APACHE2.4.9、MYSQL5.6.16),未经许可禁止转载!
参考:http://httpd.apache.org/docs/current/mod/mod_deflate.html
参考:http://note.t4x.org/system/configure-httpd-MySQL-php/
参考:http://note.t4x.org/system/apache-mod-expires/ SourceByrd's Weblog-https://note.t4x.org/environment/apache-mod-deflate/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!
Trackbacks