Gzip is a file compression format with the. Gz,http protocol to improve Web application performance, speed up the download of HTTP request content, increase user experience, and reduce network bandwidth consumption
Apache has a built-in mod_deflate module to enable gzip, but if you do not compile the relevant modules when you install Apache, you will need to manually install it once to enable it:
First to your Apache source directory, find the mod_deflate.c file
Mac and Linux are available locate mod_deflate.c
Usual Location: apachehttpd source Directory/modules/filters/mod_deflate.c
Go to the directory found above run the following command:
/usr/local/apache/bin/apxs-i-c-a mod_deflate.c
Note: Apxs directory Please refer to your own machine, usually in the Apache installation directory in the bin directory
Installation completed, to the Apache modules directory to see if there is a mod_deflates.so, if you have this file, please edit the Apache installation directory conf/httpd.conf configuration file:
LoadModule Deflate_module modules/mod_deflate.so
Load mod_deflate.so Module
Add the following additions to the site configuration in httpd.conf:
Addoutputfilterbytype DEFLATE text/html text/plain text/css text/xml
Deflatecompressionlevel 9
Setoutputfilter DEFLATE
The first line represents what content is enabled for gzip compression, the second line represents the compression level, and the third line enables the Deflate module to gzip the output of this site (that is, to enable compression for all outputs)
OK, complete pull, restart Apache httpd can find some gzip detection site for some effect, usually compression rate is more than%50, can effectively increase access speed and site bandwidth utilization, good luck!
Problems that may be encountered:
Question: After Apache startup problem, the log appears mod_deflate.so:undefined Symbol:inflateend
Resolution: Increase loadfile/usr/local/lib/libz.so or loadfile/usr/lib/libz.so before LoadModule deflate_module modules/mod_deflate.so
Note: Specific libz.so position find yourself
Mod_deflate is the standard filter module in Apache2, the function of which is the same as that of Mod_gzip: compressing the various components of Web pages and speeding up the download speed of Web pages.
Typically, adding modules in Apache2 does not require you to recompile Apache, just dynamically adding the required modules is OK. First find the mod_deflate.c file in the Modules folder of the Apache source installation folder ...
In Apache2.2.2, the Mod_deflate module is located in the Modules/filters folder, after the position is determined:
| The code is as follows |
Copy Code |
|
[Root@localhost modules]# Cd/apache-source-install-path/modules/filters
[Root@localhost filters]#/apache-installed-path/bin/apxs-i-a-c mod_deflate.c
If the installation succeeds, you will be prompted:
chmod 755/apache-installed-path/modules/mod_deflate.so
[Activating module ' deflate ' in/apache-installed-path/conf/httpd.conf] |
At this point, open the/apache-installed-path/conf/httpd.conf file and search for "mod_deflate", as you can see that the module is already loaded, as follows:
LoadModule Deflate_module modules/mod_deflate.so
Now that the module is loaded, you can compress the desired content. Apache official has detailed mod_deflate configuration instructions, the following is my test site to do mod_deflate configuration:
| The code is as follows |
Copy Code |
|
<ifmodule mod_deflate.c>
Deflatecompressionlevel 9 #压缩的级别设置为最高
#将html, text, XML, PHP compression
Addoutputfilterbytype DEFLATE text/html text/plain text/xml application/x-httpd-php
# compress HTML, htm, XML, PHP, CSS, JS
Addoutputfilter DEFLATE HTML htm xml php css JS
</IfModule> |
Apache2 Add mod_deflate compression module so that's OK. Of course, the above modifications to httpd.conf should save the file and restart the Apache service. This time again through some HTTP observation software to see if the page has been compressed. The following is my screenshot of Northwestern University test site enabled Mod_deflate to compress the results:
Mod_deflate Compression Results
The experiment proves that the Mod_deflate module of Apache can compress the content of the Web page and reduce the page size to about 60%. Especially for non-picture, not multimedia-oriented web site more obvious effect