Enable gzip of apache2

Source: Internet
Author: User
Document directory
  • Correct differentiation between mod_deflate and mod_gzip
  • Enable gzip of apache2
  • More Customization
  • Supplement
Enable the gzip function of apache2

Gzip greatly reduces the bandwidth (about 60%-75%) of webpages during transmission while consuming a little CPU usage ). Recently, I have been tossing around the ctusky website opening speed. I am always very concerned about the opening speed. The following describes how to enable gzip compression in apache2.

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.

Enable gzip of apache2

Compile and install apache2.2.xx: Add-enable-Deflate = shared when compiling the source code.
The following lines are found in HTTP. conf. If not, add

LoadModule deflate_module modules/mod_deflate.so

If Yum rpm is installed, the compression ratio is automatically enabled. compression ratio: approximately 70% of the volume can be compressed.

More Customization

The compression function is enabled. It can be used very well. For more detailed customization, see the following:
You can add this section after HTTP. conf for customization: (if not necessary, use the default one)

<ifmodule mod_deflate.c>
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE js css
</ifmodule>

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
 
As of time, the difference is not very big, and it is about 10-20 seconds.

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.