Enable Gzip compression for Apache in Centos

Source: Internet
Author: User
Correct distinction between mod_deflate and mod_gzip is called gzip. In fact, in earlier versions of apache1.x, there was no built-in web page compression technology. Therefore, gzip compression is required. during official development of apache2, the page compression has been taken into account and the mod_deflate module has been built in. Therefore, apache2 does not need to use mod_gzip. the working principles of the two are similar, and the module that enables the mod_deflate web page compression is also used, functions and

Correct differentiation between mod_deflate and mod_gzip

The so-called gzip is actually in the early stage of apache 1. there is no built-in web page compression technology in the x series, so gzip compression is required. when the official development of apache2 takes the web page compression into consideration, the mod_deflate module is built in, therefore, apache2 does not need to use mod_gzip. The working principle of the two is similar. In addition, the module that enables mod_deflate to compress the webpage has similar functions and efficiency as mod_gzip, and even better, you do not need to use the mod_gzip module.

1. check whether the mod_deflate module has been loaded in apache.

# Httpd-M

Check whether a field such as deflate_module (shared) exists in the result. If yes, the module has been successfully added. If you do not need to install and load the mod_deflate module first.

2. edit the configuration file httpd. conf and add a file type that supports gzip, as shown below:


DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE text/html text/xml application/x-httpd-php
AddOutputFilter DEFLATE js css

 

This will compress the html, xml, php, css, js, and other file output formats used in general web pages, although it will take up a little bit of processing time of the server processor, when receiving web page data, the browser consumes a very short processor time, but it can greatly reduce the data transmission volume and reduce the consumption of network bandwidth.

DeflateCompressionLevel 9 refers to the compression level, from 1 to 9, 9 is the highest level. It is understood that this can reduce the transmission volume by up to 8 characters (depending on the file content), and reduce the transmission volume by at least half.

By default, DeflateCompressionLevel can use the value 6 to maintain a balance between the consumed processor performance and the web page compression quality.

Supplement

As for the formats of compressed images such as jpg, music files such as mp3, compressed files such as zip, there is no need to compress them, because this type of file is compressed when you open the server, the processor time will not be enough, and even if you finish running, the size will be the same. if you use PHP functions and other compressed files, httpd services will not be compressed again. system-level processing is always more efficient than application-level processing.

Comparison between mod_deflate and gzip compression of Apache.

* No compression: kilobytes KB
* Use gzip only: 323KB
* Only use the deflate module of Apache: 247KB
* Use deflate and gzip at the same time: 247KB

Save and exit

3. restart Apache

Service httpd restart

4. check whether the gzip function is correctly enabled.

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.