This article introduces how to enable gzip in centos apache. If you need it, refer to it.
The method for enabling gzip compression is simple. Connect to the server and open the configuration file "httpd. conf". Find the following two sentences and remove the previous "#"
The Code is as follows: |
Copy code |
LoadModule deflate_module modules/mod_deflate.so LoadModule headers_module modules/mod_headers.so
|
Add the following statement at the end of the configuration file:
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 .(? : Pdf | 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 enable File compression.
The last three sentences are the files that do not need to be compressed. jpg, gif, and png images are compressed. Then, gzip compression will increase the burden on the server.
Method in linux
1. Check whether the mod_deflate module has been loaded in apache.
1. httpd-M
How this module is not in the list,
How to install and load the mod_deflate module.
The mod_deflate module must be installed and loaded. This section describes how to install the SDK.
1. Go to the mod_deflate.c directory.
The Code is as follows: |
Copy code |
1. cd/lamp/httpd-2.2.20/modules/filters
|
2. Execute the compilation and 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. Check whether the load is successful.
The Code is as follows: |
Copy code |
1. httpd-M
|
2. Compile the configuration file httpd. conf and add a file type that supports gzip, as shown below:
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. Check whether it has been enabled successfully.
How to enable gzip in windows
Http://www.bKjia. c0m/phper/apache/apache-gzip.htm