Gzip Compression on Centos 6

April 6, 2015 6.9k views
Caching Linux Basics Server Optimization Getting Started DigitalOcean Linux Commands CentOS

I have created a server on the centos 6 platform 64 bit and we are currently trying to enable the gzip compression to make our website load faster. Now we have read several different articles to make sure this works first we needed to make sure that module was installed we checked that and it does show as being installed and we also heard that by default it's installed with the setup of the server we are running the vesta control panel. Based off our research you can set the compression by either doing it on the server or by doing it in the htaccess file so we tried adding it on the server side we tried adding the following code "AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript" in the following file "/etc/httpd/conf/httpd.conf" and still came back with no results every time we do this we are restarting apache to see if it's takes effect we even rebooted the entire server to make sure everything restarts. We have also tried putting that code in the"/home/admin/conf/web/httpd.conf" as well with the same no results. If somebody can give a step by step on what we may be doing wrong maybe there's a way to check if gzip is installed with certain commands and also which file do we actually modify to make the compression work. thank you.

4 Answers

First make sure you have this line in httpd.conf

LoadModule deflate_module modules/mod_deflate.so

Create a new file in /etc/httpd/conf.d called deflate.conf and add the following contents.

#Set to gzip all output
SetOutputFilter DEFLATE

#exclude the following file types
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|iso|tar|bz2|sit|rar|png|jpg|gif|jpeg|flv|swf|mp3)$ no-gzip dont-vary

#set compression level
DeflateCompressionLevel 9

#Handle browser specific compression requirements
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0

ensure you include this file in your httpd.conf

To check gzip I recommend http://checkgzipcompression.com/

  • ok we have done everything you mentioned can you clarify on the very last step will you said ensure you include this in your httpd.conf. We checked the code for the first step it's already in the httpd.conf file and the we created the deflate.conf file and copied that code saved it and rebooted the server but that last step we didn't get.

I just mean check that conf.d and sub folders are on the same line as an Include statement that should enable gzip compression for you.

ok i went into the httpd.conf file and i found this already in the file "Include conf.d/*.conf" is this what you mean or should i add another include pointing to that specific file.

Thats exactly what I mean. You should have Compression enabled then (if the browser supports it)

  • ok thank you for your help i really appreciate it. We will let yo know how everything comes out.

Have another answer? Share your knowledge.