您的位置主页 > 系统管理

Apache配置gzip压缩(HTTP压缩)功能

2011-06-25 17:30:14
针对Apache2.0之前的版本,它原本是不支持的,不过可以通过添加第三方的module_gzip模块来启用
针对Apache2.0及之后的版本,Apache提供支持, 不过不叫gzip,而叫mod_deflate
下面就对Apache2.0及之后的版本作一个说明
1) 去掉#LoadModule headers_module modules/mod_headers.so前面的注释#,
2) 添加LoadModule deflate_module modules/mod_deflate.so
3) 在VirtualHost中添加
[size=13px][color=#008080]1[/color][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img]
[color=#0000ff]<[/color][color=#800000]Location [/color][color=#ff0000]"/"[/color][color=#0000ff]>[/color]
[color=#008080]2[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] SetOutputFilter DEFLATE
[/color][color=#008080]3[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] BrowserMatch ^Mozilla/4 gzip-only-text/html
[/color][color=#008080]4[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] BrowserMatch ^Mozilla/4\.0[678] no-gzip
[/color][color=#008080]5[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
[/color][color=#008080]6[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
[/color][color=#008080]7[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] Header append Vary User-Agent env=!dont-vary
[/color][color=#008080]8[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]</[/color][color=#800000]Location[/color][color=#0000ff]>[/color]
[color=#008080]9[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img][/color][/size]

我这里面有一个完整的演示
[size=13px][color=#008080]1[/color][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img][color=#000000]# 加载deflate模块
[/color][color=#008080]2[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img]LoadModule headers_module modules/mod_headers.so
[/color][color=#008080]3[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img]LoadModule deflate_module modules/mod_deflate.so
[/color][color=#008080]4[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img][/color][color=#0000ff]<[/color][color=#800000]VirtualHost [/color][color=#ff0000]*:80[/color][color=#0000ff]>[/color]
[color=#008080]5[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] DocumentRoot f:/apacheTest
[/color][color=#008080]6[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]<[/color][color=#800000]Location [/color][color=#ff0000]"/"[/color][color=#0000ff]>[/color]
[color=#008080]7[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] SetOutputFilter DEFLATE
[/color][color=#008080]8[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] BrowserMatch ^Mozilla/4 gzip-only-text/html
[/color][color=#008080]9[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] BrowserMatch ^Mozilla/4\.0[678] no-gzip
[/color][color=#008080]10[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
[/color][color=#008080]11[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
[/color][color=#008080]12[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] Header append Vary User-Agent env=!dont-vary
[/color][color=#008080]13[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]</[/color][color=#800000]Location[/color][color=#0000ff]>[/color]
[color=#008080]14[/color][color=#000000][img]http://www.blogjava.net/Images/OutliningIndicators/None.gif[/img][/color][color=#0000ff]</[/color][color=#800000]VirtualHost[/color][color=#0000ff]>[/color][/size]