---
title: "win2003中Apache开启gzip功能"
author: "2002wmj"
date: "2011-10-19T14:32:06Z"
tags: ["Apache", "gzip"]
categories: ["操作系统"]
slug: "win2003-apache-gzip"
draft: false
lastmod: "2011-10-19T14:43:52Z"
id: 1201696
url: "https://2002wmj.iteye.com/blog/1201696"
---

一直觉得网站访问速度很慢，打开0.6秒，打开GZIP后打开只要0.1秒，非常不错！

 

 

HTTP 压缩可以大大提高浏览网站的速度，它的原理是，在客户端请求网页后，从服务器端将网页文件压缩，再下载到客户端，由客户端的浏览器负责解压缩并浏览。相对于普通的浏览过程HTML ,CSS,Javascript , Text ，它可以节省40%左右的流量。更为重要的是，它可以对动态生成的，包括CGI、PHP , JSP , ASP , Servlet,SHTML等输出的网页也能进行压缩，压缩效率惊人!!

１）针对Apache2.0之前的版本，它原本是不支持的，不过可以通过添加第三方的module\_gzip模块来启用  
２）针对Apache2.0及之后的版本，Apache 提供支持, 不过不叫gzip，而叫mod\_deflate  
下面就对Apache2.0及之后的版本作一个说明。

1.开启 gzip模块  
   LoadModule deflate\_module modules/mod\_deflate.so  
2\. 在httpd.conf中增加下面的内容：  
&lt;Location /&gt;  
    # 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  
    BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html  

    # Don't compress images  
    SetEnvIfNoCase Request\_URI \\.(?: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  
&lt;/Location&gt;

3\. 重启Apache进程即可。