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