Enable Apache to implement the gzip compression configuration

  • 2020-05-09 19:49:14
  • OfStack

As we all know, gzip compression is supported in HTTP1.1, which can reduce the page size and speed up the page display. Use this online HTTP compression test tool to check if your site has started gzip compression.

Apache default http.conf configuration file does not turn on gzip compression, apache1.3.x can use mod_gzip to optimize the speed of web browsing, apache2 also tried to use mod_gzip, but the configuration found that the page can not display correctly (blank page), so it was changed to mod_deflate.

Here's how to turn on gzip compression under Apache2:


# loading deflate The module
LoadModule deflate_module modules/mod_deflate.so
# Set the compression frequency, the value range is 1( Minimum compressibility ) to 9( Maximum compressibility ) between
# It is not recommended to set too high, although it has a high compression rate, but it takes up more CPU resources
DeflateCompressionLevel 3
# Compress everything except images
<Location />
# Insertion filter
SetOutputFilter DEFLATE
 
# Netscape 4.x There are 1 Some problems ...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 There are more questions
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE Will be disguised as a Netscape ", but in fact there is nothing wrong with it
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Uncompressed picture
SetEnvIfNoCase Request_URI \\.(?:gif|jpe?g|png)$ no-gzip dont-vary
</Location>

After the above Settings, HTTP compression is turned on in Apache. Does the speed of page display increase a lot?


Related articles: