Linux CentOS Apache to open gzip method

Source: Internet
Author: User
Tags centos

The way to turn on gzip compression is simple, connect the server and open the configuration file "httpd.conf", find the following two sentences, remove the "#" in front

The code is as follows Copy Code
LoadModule Deflate_module modules/mod_deflate.so
LoadModule Headers_module modules/mod_headers.so

At the end of the configuration file, add the following statement:

The code is as follows Copy Code
<ifmodule deflate_module>
Setoutputfilter DEFLATE
Setenvifnocase Request_uri. (?: gif|jpe?g|png) $ no-gzip dont-vary
Setenvifnocase Request_uri. (?: Exe|t?gz|zip|bz2|sit|rar) $ no-gzip dont-vary
Setenvifnocase Request_uri. (?:p df|doc|avi|mov|mp3|rm) $ no-gzip dont-vary
Addoutputfilterbytype DEFLATE text/html text/plain text/xml text/css
Addoutputfilterbytype DEFLATE Application/x-javascript
</IfModule>

The first sentence is to turn on file compression

The third sentence is to set the file without compression, JPG, GIF, PNG image is already compressed, and then use gzip compression will increase the burden on the server, can not get stuck

Method in Linux

1, first have to confirm whether Apache has loaded the Mod_deflate module.

1.httpd-m
How this module is not in the list,

How to install the Load mod_deflate module.

The Mod_deflate module must be installed to load. Now describes how to install.

1, into the mod_deflate.c directory

The code is as follows Copy Code
1.cd/lamp/httpd-2.2.20/modules/filters

2. Execute the compiler loading program

The code is as follows Copy Code
1./usr/local/apache/bin/apxs-i-a-c mod_deflate.c

3. Restart the HTTPD program

The code is as follows Copy Code
1.service httpd Restart

4. See if it has been loaded successfully

The code is as follows Copy Code
1.httpd-m

2, compile the configuration file httpd.conf, increase the support gzip file type, as follows:

The code is as follows Copy Code
<location/>
Addoutputfilterbytype DEFLATE Text/plain
Addoutputfilterbytype DEFLATE Text/css
Addoutputfilterbytype DEFLATE Application/xml
Addoutputfilterbytype DEFLATE Application/rss+xml
Addoutputfilterbytype DEFLATE Application/atom_xml
Addoutputfilterbytype DEFLATE Application/x-javascript
Addoutputfilterbytype DEFLATE application/x-httpd-php
Addoutputfilterbytype DEFLATE text/html
</Location>

Restart httpd.

The code is as follows Copy Code

Service httpd Restart


4, whether the test has been opened successfully.

Windows to open gzip method

Http://www.111cn.net/phper/apache/apache-gzip.htm

Related Article

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.