---
title: "Apache2.x中设置gzip"
author: "JetMah"
date: "2010-12-01T13:26:16Z"
tags: []
categories: ["Web前端"]
slug: "apache2-x-gzip"
draft: false
lastmod: "2010-12-01T13:26:16Z"
id: 830339
url: "https://jetma.iteye.com/blog/830339"
---

原文出处: [Apache2.x中设置gzip](http://www.javatang.com/archives/2010/12/01/2805477.html)  
作者: Jet Mah from [Java堂](http://www.javatang.com/)  
声明: **可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明！**

在Apache2.x中使用mod\_deflate进行gzip压缩，配置信息如下：

 

01. LoadModule deflate\_module modules/mod\_deflate.so
02. LoadModule headers\_module modules/mod\_headers.so
03. \# gzip 设置
04. \# Only compress specified content type
05. \# see also http://www.devside.net/guides/config/compression
06. &lt;IfModule mod\_deflate.c&gt;
07. \# The value must between 1 (less compression) and 9 (more compression)
08. DeflateCompressionLevel 7
09. \# compress content with type html, text, and css
10. AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php application/json
11. \# place filter 'DEFLATE' on all outgoing content
12. SetOutputFilter DEFLATE
13. \# Properly handle old browsers that do not support compression
14. BrowserMatch ^Mozilla/4 gzip-only-text/html
15. BrowserMatch ^Mozilla/4\\.0\[678] no-gzip
16. BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html
17. &lt;/IfModule&gt;

 

参考资料：  
[apache 2.2.15中配置mod\_deflate](http://jackyrong.iteye.com/blog/797656)  
[httpd.conf — compression](http://www.devside.net/guides/config/compression)