enabling gzip (mod_deflate) on Apache (dedicated server runinng plesk 9)

george82 used Ask the Experts™

Can someone help me enable gzip content compression on html/css/js using gzip ?

I am running CentOS on my dedicated server and Plesk 9

I would like to see how I can enable gzip on a single virtual host instead of the whole server.

Thank you

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Monis MontherSystem Architect
1- make sure this line is un hashed (This enables the module)
Under httpd.conf

LoadModule deflate_module modules/mod_deflate.so

2- Under Your Virtual Host under your Directory where compression is to be enabled

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript


3- (Optional ) you can add logging for deflate to verify and confirm that it is compressing

After the </Directory>

DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog /var/log/httpd/deflate_log deflate

Herre your log file is /var/log/httpd/deflate_log

Note: Its better to disable its logging once proven to work to avoid un-necessary writes to the disk
Senior Technical Engineer
To addon to small_student and make it more simple create a file for all mod_deflate related configs file and just add it to httpd.conf, in this way you just need to copy and add the file name to httpd.conf to enable compression. By this you will be able to configure easily and organised and migrate configs hassle free.Please follow below steps.

Enabling Web Compression

To enable web compression, we need to create a mod_deflate.conf file and also do some changes to the web server configuration - httpd.conf file.

To create the mode_deflate.config, perform the following operations:
1.      Create mod_deflate.conf file. The contents of the file are provided below:
<Location />
# Insert filter
#Comment SetOutputFilter and
#uncomment AddOutputFilterByType to disable js files compression
SetOutputFilter DEFLATE
#AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary


DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio

#If <VirtualHost> defined then add below log config in <VirtualHost>
#Othewise uncomment here to enable deflate log
#CustomLog <APACHE_HOME>Apache/logs/deflate.log \
#          '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)'
2.      If VirtualHost defined then add the log directive in that section. For secure web server add the following after ssl_request_log definition.
CustomLog <APACHE_HOME>/Apache/logs/deflate.log \
          '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)'
a.      This step is optional and can be skipped.
b.      Change the path to the log file as per your server setup.

3.      Save and close mod_deflate.conf file.
4.      Check the ownership for the file mod_deflate.conf, the web server admin should have rights for this file; change ownership if required.
5.      Restart web server.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial