[乐意黎原创]Centos主机里为Apache添加页面压缩mod_deflate模块开启gzip压缩

mod_deflate 是apache自带的模块,当然是在apache2后支持的,以前1的时候是mod_gzip,启用mod_deflate可以很好的为节省网页大小,只不过是占用服务器的资源和内存.用户看到页面的速度会大大加快.

提高网站速度除制作时减少冗余代码、进一步精简网页、CSS文件外,压缩输入也是一个不错的方法。deflate是apache自带的压缩模块,可以对动态输出内容或者静态内容(如HTML、JS、CSS等)进行压缩,减少网络传输量,从而提高响应速度,也提高了系统负载能力。

mod_filter过滤模块也扩展了功能,允许过滤器根据有条件的规定运行。这就改动了以前的旧模式。根据旧模式,只能根据AddOutputFilter指令的设置无条件地对文件实施过滤,或根据AddOutputFilterByType指令稍微灵活一点地对文件实施过滤。


安装 Apache时请注意 开启 mod_deflate, 我的就是忘了。
请参考:  https://blog.csdn.net/aerchi/article/details/72777795

安装环境:

apache 的filters 源路径:  /usr/local/src/httpd-2.4.23/modules/filters
apache 安装路径:   /usr/local/apache

1. 安装 mod_deflate.so

[root@aerchi.com ~]# cd /usr/local/src/httpd-2.4.23/modules/filters
[root@aerchi.com filters]# /usr/local/apache/bin/apxs -i -c -a mod_deflate.c
/usr/local/apr/build-1/libtool --silent --mode=compile gcc -std=gnu99 -prefer-pic   -DLINUX -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/apache/include  -I/usr/local/apr/include/apr-1   -I/usr/local/apr-util/include/apr-1   -c -o mod_deflate.lo mod_deflate.c && touch mod_deflate.slo
/usr/local/apr/build-1/libtool --silent --mode=link gcc -std=gnu99    -o mod_deflate.la  -rpath /usr/local/apache/modules -module -avoid-version    mod_deflate.lo
/usr/local/apache/build/instdso.sh SH_LIBTOOL='/usr/local/apr/build-1/libtool' mod_deflate.la /usr/local/apache/modules
/usr/local/apr/build-1/libtool --mode=install install mod_deflate.la /usr/local/apache/modules/
libtool: install: install .libs/mod_deflate.so /usr/local/apache/modules/mod_deflate.so
libtool: install: install .libs/mod_deflate.lai /usr/local/apache/modules/mod_deflate.la
libtool: install: install .libs/mod_deflate.a /usr/local/apache/modules/mod_deflate.a
libtool: install: chmod 644 /usr/local/apache/modules/mod_deflate.a
libtool: install: ranlib /usr/local/apache/modules/mod_deflate.a
libtool: finish: PATH="/usr/local/node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/apache/bin:/usr/local/mysql/lib:/sbin" ldconfig -n /usr/local/apache/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/apache/modules


If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'


See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache/modules/mod_deflate.so
[activating module `deflate' in /etc/httpd/httpd.conf]

--------------------------------------------------------------------------------------------------

至此 mod_deflate.so 安装完成.


2. 启用 mod_deflate.so


[root@aerchi.com filters]#   vim /etc/httpd/httpd.conf

(1. 去掉apache配置文件httpd.conf以下代码前的“#”

#下行如没有,则添加
LoadModule deflate_module modules/mod_deflate.so 
LoadModule headers_module modules/mod_headers.so
LoadModule filter_module modules/mod_filter.so    
注意:如果mod_filter.so没有开启,apache将无法正常启动


(2.添加到httpd.conf的文件尾

<IfModule mod_deflate.c>
     SetOutputFilter DEFLATE
     AddOutputFilterByType DEFLATE text/html text/css application/x-javascrip    t application/json

</IfModule>

ECS,    :wq 保存
重启apache,   
[root@aerchi.com]#   apachectl restart

重新打开网页,查看:



----------------------------------------

乐意黎
2018-07-06

发布了430 篇原创文章 · 获赞 415 · 访问量 925万+
展开阅读全文

编译安装apache遇到问题

01-23

Making all in support make[1]: Entering directory `/root/httpd-2.4.29/support' make[2]: Entering directory `/root/httpd-2.4.29/support' /usr/local/apr/build-1/libtool --silent --mode=compile gcc -std=gnu99 -g -O2 -pthread -DLINUX -D_REENTRANT -D_GNU_SOURCE -I. -I/root/httpd-2.4.29/os/unix -I/root/httpd-2.4.29/include -I/usr/local/apr/include/apr-1 -I/usr/local/apr-util/include/apr-1 -I/root/httpd-2.4.29/modules/aaa -I/root/httpd-2.4.29/modules/cache -I/root/httpd-2.4.29/modules/core -I/root/httpd-2.4.29/modules/database -I/root/httpd-2.4.29/modules/filters -I/root/httpd-2.4.29/modules/ldap -I/root/httpd-2.4.29/modules/loggers -I/root/httpd-2.4.29/modules/lua -I/root/httpd-2.4.29/modules/proxy -I/root/httpd-2.4.29/modules/session -I/root/httpd-2.4.29/modules/ssl -I/root/httpd-2.4.29/modules/test -I/root/httpd-2.4.29/server -I/root/httpd-2.4.29/modules/arch/unix -I/root/httpd-2.4.29/modules/dav/main -I/root/httpd-2.4.29/modules/generators -I/root/httpd-2.4.29/modules/mappers -prefer-non-pic -static -c htpasswd.c && touch htpasswd.lo /usr/local/apr/build-1/libtool --silent --mode=compile gcc -std=gnu99 -g -O2 -pthread -DLINUX -D_REENTRANT -D_GNU_SOURCE -I. -I/root/httpd-2.4.29/os/unix -I/root/httpd-2.4.29/include -I/usr/local/apr/include/apr-1 -I/usr/local/apr-util/include/apr-1 -I/root/httpd-2.4.29/modules/aaa -I/root/httpd-2.4.29/modules/cache -I/root/httpd-2.4.29/modules/core -I/root/httpd-2.4.29/modules/database -I/root/httpd-2.4.29/modules/filters -I/root/httpd-2.4.29/modules/ldap -I/root/httpd-2.4.29/modules/loggers -I/root/httpd-2.4.29/modules/lua -I/root/httpd-2.4.29/modules/proxy -I/root/httpd-2.4.29/modules/session -I/root/httpd-2.4.29/modules/ssl -I/root/httpd-2.4.29/modules/test -I/root/httpd-2.4.29/server -I/root/httpd-2.4.29/modules/arch/unix -I/root/httpd-2.4.29/modules/dav/main -I/root/httpd-2.4.29/modules/generators -I/root/httpd-2.4.29/modules/mappers -prefer-non-pic -static -c passwd_common.c && touch passwd_common.lo /usr/local/apr/build-1/libtool --silent --mode=link gcc -std=gnu99 -g -O2 -pthread -o htpasswd htpasswd.lo passwd_common.lo /usr/local/apr-util/lib/libaprutil-1.la /usr/local/apr/lib/libapr-1.la -lrt -lcrypt -lpthread -ldl -lcrypt /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler' collect2: error: ld returned 1 exit status make[2]: *** [htpasswd] Error 1 make[2]: Leaving directory `/root/httpd-2.4.29/support' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/root/httpd-2.4.29/support' make: *** [all-recursive] Error 1 [root@bogon httpd-2.4.29]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-rewrite --libdir=/usr/lib64^C [root@bogon httpd-2.4.29]# ll /usr/lib/libm libm-2.17.so libmemusage.so libm.so.6 [root@bogon httpd-2.4.29]# ll /usr/lib/libelf libelf-0.168.so libelf.so.1 [root@bogon httpd-2.4.29]# ll /usr/lib/libelf libelf-0.168.so libelf.so.1 ----------------以上为make后的信息------------- 安装根据http://blog.csdn.net/bizu005/article/details/78339380?locationNum=4&fps=1教程进行操作 环境如下:Centos7.4 编译安装的apache版本为2.4.29 已执行过的操作: 1.安装依赖包yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel 2.添加配置 --libdir=/usr/lib64 3.根据http://www.ti6.net/wangzhanjishu/1587.html所示,但是并未在mv /usr/lib/路径下 找到 libm.a,libm.so,libexpat.so只有一下文件libm-2.17.so libmemusage.so libm.so.6 ![图片说明](https://img-ask.csdn.net/upload/201801/23/1516697165_357009.png) 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览