Compression using mod_deflate in Apache

A compression filter optimizes the size of the content that you send from your web server to a user via the Internet. This will save lots of bandwidth and so the application will be a lot faster as the content will be transfered to browser pretty soon. This task can be performed by turning mod_deflate module on.
To set mod_deflate I added following block in httpd.conf, This file can be found in /conf/httpd.conf.

1. Load deflate_module module. It might be commented in the beginning of the file. Uncomment if commented.

LoadModule deflate_module modules/mod_deflate.so

2. Set compression filter

<Location />
  <IfModule mod_deflate.c>
   SetOutputFilter DEFLATE
  # file-types indicated will not be compressed
   SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip|pdf)$ no-gzip dont-vary
    <IfModule mod_headers.c>
      Header append Vary User-Agent
    </IfModule>
  </IfModule>
</Location>

3. Create a new log file to check compression results, it can be done by placing following code in httpd.conf. You need to make sure that mod_log_config is included in httpd.conf.

<IfModule mod_log_config.c>
  <IfModule mod_deflate.c>
    DeflateFilterNote Input instream
    DeflateFilterNote Output outstream
    DeflateFilterNote Ratio ratio
    SetEnvIf Request_URI \.gif image-request
    SetEnvIf Request_URI \.js image-request
    SetEnvIf Request_URI \.css image-request
    LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
    CustomLog logs/deflate.log deflate env=!image-request
  </IfModule>
</IfModule>

I have verified compression with & without ssl mode and don’t find any problem.

Related Post

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
Installing tomcat in ubuntu/linux
javax.servlet.ServletException: javax.naming.NameNotFoundException: Name comp is not bound in this Context
java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
Forcing www in url using Apache

Comments

Leave a Reply




Technology