首页 > 服务器 > Apache性能优化–开启gzip压缩

Apache性能优化–开启gzip压缩

2010年8月26日 阅读(1,552 ) 发表评论 阅读评论

为了使网站浏览速度更快,对apache启用了gzip压缩功能,虽然这多少会给服务器造成一定的压力,但还是可以承受的,哈,看看怎么来给Apache开启gzip压缩功能(我的是在windows下.用的版本是Apache2.0.47.0)吧:
Apache开启gzip压缩功能需要用到模块mod_deflate.so,你可以到%Apache安装路径%/modules文件夹下找到mod_deflate.so这样一个文件。在 %Apache安装路径%/conf 下的httpd.conf文件里面是没有加载这一模块的,所以你必须手动进行配置,在httpd.conf文件里面添加上以下内容:
#加载mod_deflate.so模块
LoadModule deflate_module modules/mod_deflate.so
#对text/html text/php text/png text/jpg text/plain text/css text/xml text/javascript
#启用GZIP压缩
AddOutputFilterByType DEFLATE text/html text/php text/png text/jpg text/plain text/css text/xml text/javascript
#压缩级别 9 性能最佳
DeflateCompressionLevel 9
#启用deflate模块对本站点的所有输出进行GZIP压缩
SetOutputFilter DEFLATE

最后重启Apache就可以了。。。

下面摘抄一下网上介绍的在linux下开启gzip压缩功能的文章内容:
而如果是 Linux/Unix 操作系统,如果你没有在编译安装的过程中将所需要的两个模块 mod_deflate 和 mod_headers 编译进去的话,那就稍微有点麻烦,首先我们先看如何在编译安装 Apache 过程中也同时编译这两个模块,请在执行 configure 程序时增加两个参数分别是:

# ./configure –enable-deflate –enable-headers
这样在编译完 Apache 后就可以直接在 httpd.conf 中启用并配置 deflate 模块了,配置的方法跟 Windows 平台下是相同的。
如果说您的 Apache 已经在运行了,不想再重新编译一次,那也可以选择只编译 deflate 模块所需的文件 mod_deflate.c 和 mod_headers.c。这两个文件位于 {apache-src}/modules/filters/ 目录下(其中 {apache-src} 为 apache 源文件所在的目录)。使用如下命令来单独编译这两个源文件。

# {apache-bin}/apxs -i -a -c {apache-src}/modules/filters/mod_deflate.c
# {apache-bin}/apxs –i –a –c {apache-src}/modules/filters/mod_headers.c
When install the header module the src directory is {apache-src}/modules/metadata/mod_headers.c
So we need change the command as follows:{apache-bin}/apxs -i -a -c {apache-src}/modules/metadata/mod_headers.c

其中 {apache-bin} 为 Apache 安装目录下的 bin 目录,接下来在 httpd.conf 直接配置该模块即可。
很多时候你在单独编译 deflate 模块的时候可能会碰到编译错误,提示是:
Cannot load /opt/apache/modules/mod_deflate.so into server: /opt/apache/modules/mod_deflate.so: undefined symbol: deflate
解决的方法如下:
编辑 /usr/local/apache2/bin/apr-config 文件修改其中的 LDFLAGS 值为 “-lz”,然后再重新编译 mod_deflate 模块,apxs -ica mod_deflate.c 即可。
为了省却不必要的麻烦,请尽量在编译安装时直接加上 –enable-deflate –enable-headers 参数。


声明:转载原创文章时请注明:
    文章转载自:快乐心情, 原文地址:Apache性能优化–开启gzip压缩

分类: 服务器 标签: ,

Related Posts

  1. 2010年9月3日18:50 | #1

    哎呀,想知道,就得问,问了才知道

  2. 2010年9月24日16:14 | #2

    很不错!

  3. 2010年10月7日09:30 | #3

    文章写的不错,特来顶一下!!

  4. 2011年6月10日09:20 | #4

    虚拟主机怎么办啊,怎么看看模块是否开启

  1. 本文目前尚无任何 trackbacks 和 pingbacks.
icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif