日期:2014-05-16  浏览次数:20802 次

apache 压缩技术与配置(一)

在apache 的配置文件 httpd.conf 中的末尾添加如下信息:

?

<Location "/">

?

# Insert filter
?? SetOutputFilter DEFLATE

?

# Netscape 4.x has some problems...
?? BrowserMatch ^Mozilla/4 gzip-only-text/html

?

# Netscape 4.06-4.08 have some more problems
?? BrowserMatch ^Mozilla/4\.0[678] no-gzip

?

# MSIE masquerades as Netscape, but it is fine

# BrowserMath \bMSIE !no-gzip !gzip-only-text/html

?

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48

# the above regex won't work. You can use the following

# workaround to get the desired effect:
?? BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

?

# Don't compress images
?? SetEnvIfNoCase Request_URI \.(?i:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content

?? Header append Vary User-Agent env=!dont-vary


</Location>

?

然后重启apache服务,即可!

?

?

备注:

????? 其中,以上指令当中.(?:gif|jpe?g|png|js|css|swf|bmp)$ no-gzip dont-vary 这里面表示除gif|jpe?g|png|js|css|swf|bmp类型的文件不进行压缩之外, xml/html/htm 类型的文件都可以进行压缩。

?

????? 关于mod_deflate,详细请参考 http://httpd.apache.org/docs-2.0/mod/mod_deflate.html

?

?

?

?

?

?

?

?