Before enabling Gzip, check whether the mod_deflate and mod_headers modules are loaded in the Apache configuration file.
The path to the Apache configuration file of the LAMP one-click installation script is/usr/local/apache/conf/httpd. conf.
Open this file and find the following two lines of code:
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
If there is no # symbol in front of it, it is normal. If there is # symbol, it indicates it has been commented out. Just delete the # symbol in front of it.
Add the following content at the end of the Apache configuration file/usr/local/apache/conf/httpd. conf:
<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>
Note:
IfModule deflate_module is used to determine whether the deflate_module is loaded and execute the configuration in it.
SetOutputFilter DEFLATE is the deflate compression algorithm.
SetEnvIfNoCase Request_URI is used to exclude some common image, audio, video, document, and other types of suffixes without compression.
AddOutputFilterByType DEFLATE compresses common text types, such as html, txt, xml, css, and js.
Save the modified configuration file and restart Apache.
Service httpd restart
Or
/Etc/init. d/httpd restart