登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

SeaRiver Blog

实力才是你一生最好的依靠!

 
 
 

日志

 
 

Apache deflate模块配置说明  

2007-11-27 06:50:14|  分类: apache |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

参:http://www.ceass.com/index.php?play=reply&id=90
详细解释:http://www.gccgle.com/book/apache/mod/mod_deflate.html
  

Apache deflate模块配置说明
  前几天一直在找apache2.0以dso方式编译后加载deflate模块的办法
试了apxs -ica mod_deflate.c N次,始终是报
Cannot load /opt/apache/modules/mod_deflate.so into server: /opt/apache/modules/mod_deflate.so: undefined symbol: deflate
异常的痛苦,什么ldd mod_deflate.so后再export LIB_LIBRARY_PATH呀,都试了N次,google也go了N天。终于在google上go出来一篇文章,终于解决,方法如下:
vi /usr/local/apache2/bin/apr-config
修改LDFLAGS=" " 为 LDFLAGS="-lz"
然后再apxs -ica mod_deflate.c
就OK了

以上编译完后,会在httpd.conf文件里追加以下两项:
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so

另外在配置deflate规则时
apache2.0推荐加上这句
Header append Vary User-Agent env=!dont-vary
以便确保不会输出在压缩过程中出现内容方面的error
但一般情况下,在测试apache的语法过程中会现出
Invalid command 'Header', perhaps mis-spelled or defined by a module not included in the server configuration
解决办法就是加载一个headers模块就OK了

不过最好还是在编译apache模块时直接加上--enable-deflate --enable-headers就省事多了。

一、 需求
压缩apache的输出内容,降低网站带宽
二、 加载Apache的deflate模块
1、 修改apr-config
vi /usr/local/apache2/bin/apr-config
修改LDFLAGS=" " 为 LDFLAGS="-lz"
2、 到apache源安装目录下,例如
cd /root/httpd-2.0.55/modules/filters
3、加载mod_deflate模块
/usr/local/apache2/bin/apxs -i -a -c mod_deflate.c
如果没有安装headers模块,加载headers模块
cd /root/httpd-2.0.55/modules/metadata
加载mod_headers模块
/usr/local/apache2/bin/apxs -i -a –c mod_headers.c
三、配置Apache主配置文件
1. 在httpd.conf主配置文件里添加如下行(蓝色部分)
[root@prfweb01 ~]# vi /usr/local/apache22/conf/extra/httpd-vhosts.conf
NameVirtualHost 192.168.10.21:80
<VirtualHost 192.168.10.21:80>
#   RewriteEngine On
#   RewriteCond %{REMOTE_HOST}  !^201.83.203.98
#   RewriteCond %{REMOTE_HOST}  !^201.83.203.99
#   RewriteCond %{REMOTE_HOST}  !^201.83.203.115
#   RewriteRule ^/(.*)$ http://min-yy.jp [R,L]

    ServerName min-yy.tv
    ErrorLog logs/min-yy.tv-error_log
    CustomLog "|/usr/local/apache22/bin/rotatelogs /usr/local/apache22/logs/min-yy.tv.%Y%m%d 86400 540" combined
    DocumentRoot /usr/local/apache22/htdocs/jhf_pente_web

DeflateCompressionLevel 9     ---> 指压缩程度的等级,从1到9,9是最高级别
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript   ---> 指定压缩类型
AddOutputFilter DEFLATE js css
DeflateFilterNote Input instream     ---> 声明输入流的byte数量
DeflateFilterNote Output outstream   ---> 声明输出流的byte数量
DeflateFilterNote Ratio ratio        ---> 声明压缩的百分比
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
Header append Vary User-Agent env=!dont-vary

# Don't compress images
#SetEnvIfNoCase Request_URI \.(?:gif|jpg|cab|jpe?g|exe|bmp|mp3|rar|zip|swf|png)$ no-gzip dont-vary  ---> jpg等已经压缩过的文件,就不需要再压缩了

LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate   ---> 声明日志类型
CustomLog "|/usr/local/apache22/bin/rotatelogs /usr/local/apache22/logs/deflate_log.%Y%m%d 86400 540" deflate

    <Directory /usr/local/apache22/htdocs/jhf_pente_web>
        Options FollowSymlinks
        Order allow,deny
        Allow from all
    </Directory>
    ProxyPass /flash !
    ProxyPass /css !
    ProxyPass /images !
    ProxyPass /img !
    ProxyPass /lib !
    ProxyPass /extension !
    #ProxyPass /ajax balancer://ajax/ stickysession=JSESSIONID lbmethod=byrequests maxattempts=1 nofailover=Off
    ProxyPass /ajax ajp://192.168.10.31:8009/ajax smax=2048 timeout=200 ttl=200 route=w1
    ProxyPass / balancer://min-yy/ stickysession=JSESSIONID lbmethod=byrequests maxattempts=1 nofailover=Off
    #ProxyPassReverse /ajax balancer://ajax/
    ProxyPassReverse / balancer://min-yy/
    ProxyRequests Off
    <Proxy balancer://min-yy>
        BalancerMember ajp://192.168.10.41:8009 smax=2048 timeout=200 ttl=200 route=worker1
        BalancerMember ajp://192.168.10.42:8009 smax=2048 timeout=200 ttl=200 route=worker2
        BalancerMember ajp://192.168.10.43:8009 smax=2048 timeout=200 ttl=200 route=worker3
        #BalancerMember ajp://192.168.10.44:8009 smax=2048 timeout=200 ttl=200 route=worker4
        #BalancerMember ajp://192.168.10.45:8009 smax=2048 timeout=200 ttl=200 route=worker5
        #BalancerMember ajp://192.168.10.46:8009 smax=2048 timeout=200 ttl=200 route=worker6
    </Proxy>

#<Proxy balancer://ajax>
#   BalancerMember ajp://192.168.10.31:8009/ajax smax=2048 timeout=200 ttl=200 route=w1
#   BalancerMember ajp://192.168.10.32:8009/ajax smax=2048 timeout=200 ttl=200 route=w2
#</Proxy>

</VirtualHost>

二、日志输出格式如下
[root@trffic2 logs]# tail -f access_log
"GET /apache_pb.gif HTTP/1.1" -/- (-%)
"GET /manual/ HTTP/1.1" 2163/7434 (29%)
"GET /manual/style/css/manual.css HTTP/1.1" 3973/18335 (21%)
"GET /manual/style/css/manual-loose-100pc.css HTTP/1.1" 1006/2882 (34%)
"GET /manual/style/css/manual-print.css HTTP/1.1" 2994/13017 (23%)
 
 

 

  评论这张
 
阅读(1311)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018