Modify Apache config file to turn on gzip compression transfer

Source: Internet
Author: User

Transferred from: http://down.chinaz.com/server/201202/1645_1.htm

Recently nothing to study some Web optimization, using the tool page speed detection site has not turned on gzip compression, and then surf the internet to find data to experiment; gzip compression using the Mod_deflate module in the version above apache2.0 (including apache2.0) , here are the specific configuration steps

1th Step

LoadModuledeflate_module modules/mod_deflate. SoLoadModule headers_module Modules /mod_headers.         so

After opening the httpd.conf, first the above two lines configured before the # number, so that Apache will enable the two modules, where Mod_deflate is a compression module, is to transfer to the client's code for gzip compression; mod_ The role of the headers module is to tell the browser page to use gzip compression, and if you do not turn on mod_headers, the browser will download the gzip-compressed page without displaying it properly.

2nd Step

Add the following code in the httpd.conf, you can add to any blank place, do not know the friend of Apache, if you worry about adding the wrong place, put to the last line of the http.conf file, if the virtual server can write the. htaccess file, and then put it under the project.

<IfmoduleMod_deflate. C>SetoutputfilterDEFLATE #必须的, like a switch, tells Apache to compress the content transferred to the browserSetenvifnocaseRequest_uri. (?: GIF|jpe? g|png) $ no-GzipDont-vary #设置不对后缀gif, jpg,jpeg,png image file for compressionSetenvifnocaseRequest_uri. (?: exe|t? gz|zip|bz2|sit|rar) $ no-GzipDont-vary #同上, is set not exe,tgz,gz ... The files are compressedSetenvifnocaseRequest_uri. (?:p DF|mov|avi|mp3|mp4|rm) $ no-GzipDont-vary Addoutputfilterbytypedeflate Text/* #设置对文件是文本的内容进行压缩, For example text/html text/css text/plain et  Addoutputfilterbytype DEFLATE application/ms* application/ vnd* application/postscript application/javascript application/x-javascript #这段代码你只需要了解application/javascript Application/x-javascript This paragraph is OK, this paragraph means to compress the JavaScript file  Addoutputfilterbytype DEFLATE application/x-httpd-php application/x-httpd-fastphp #这段是告诉apache对php类型的文件进行压缩  Browsermatch ^MOZILLA/4 gzip-only-text/html # Netscape 4.x There are some problems, so only the compressed file type is text/html  Browsermatch \ Bmsie!no-gzip!gzip-only-text/html # IE will disguise itself as Netscape, but in fact it's no problem </ifmodule> 

This configuration here Apache in the gzip compression is configured to complete, after restarting Apache, the new configuration will take effect. Finally with the tool to check, sure enough points to improve a lot ~ hehe. However, the ability to turn on gzip requires additional CPU resource overhead.

Modify Apache config file to turn on gzip compression transfer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.