Posts tagged How to enable mod_deflate for all domains

How to enable mod_deflate or mod_zip for all domains in Plesk

 

If you want to enable mod_deflate or mod_zip for all domains in Plesk the follow the below steps :

On a Plesk server, the mod_deflate module is installed by default, however it may be disabled in the Apache configuration file. To enable the mod_deflate module edit the Apache configuration(httpd.conf) file

[email protected][#] vi /etc/httpd/conf/httpd.conf
Search for the line
#LoadModule deflate_module modules/mod_deflate.so
and just remove the # mark
Save the file and restart the httpd service
[email protected][#] /etc/init.d/httpd restart

Now,create a deflate.conf file under the /etc/httpd/conf.d/ directory as Apache reads all the .conf files from that directory on a Plesk server

[email protected][#] vi /etc/httpd/conf.d/deflate.conf

and add the below code

<Location />
 <IfModule mod_deflate.c>
# the above makes sure that everything has loaded correctly.
# we don't want apache crashing for no good reason.

# Insert filter
 SetOutputFilter DEFLATE

 # 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 \bMSI[E] !no-gzip !gzip-only-text/html

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

 # or pdfs
 SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

 # or binary archives
 SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar|iso|dia)$ no-gzip dont-vary

 # or javascript
 SetEnvIfNoCase Request_URI \.(?:js)$ no-gzip dont-vary

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

 <IfModule mod_headers.c>
 #properly handle requests coming from behind proxies
 Header append Vary User-Agent env=!dont-vary
 </IfModule>
 </IfModule>
</Location>

Save the file and finally restart the httpd service.

The above compression code will compress all the files 
except the .gif, .jpe, .jpeg and .png files.

You can test the compression by browsing the URL :

 http://www.whatsmyip.org/mod_gzip_test/

If you want to enable compression for a specific directory or domain then specify the directory path in the directive in deflate.conf and restart the Apache server.

That’s all.