store | blogs | forums | twitter | facebook | wiki | mailing lists | downloads | support portal
Atomic Secure Linux
It is currently Fri Apr 25, 2014 4:37 am

» Feed - Atomicorp

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Apache Mod Deflate tutorial
Unread postPosted: Mon Apr 02, 2012 10:26 pm 
Offline
Forum Regular
Forum Regular

Joined: Sun Mar 29, 2009 6:52 pm
Posts: 350
I noticed that noone has discussed this topic here in the forum.

Many people (both admins and users) try to compress their websites to optimize the use of bandwidth and in order to speed up the loading proccess. Even google page speed online suggests to use compression. Many people try to do this via php but thats not very good. Best way is to do it directly from apache. This applies for anyone running apache.

I have been using it in my server for more than 6 months. It does work.
Just go to google page speed online and check for example a joomla site before and after you setup the mod deflate. I saw up to 25points difference !

First of all make sure that in your httpd.con you have loaded the mod deflate.
There shoudl be this line somewhere. If not add it !

Code:
LoadModule deflate_module modules/mod_deflate.so


Ok

Next we will create the deflate.conf

Code:
vi /etc/httpd/conf.d/deflate.conf



Next paste the following to the conf we have just created and save it.

Code:
<IfModule mod_deflate.c>
#What types must be compressed
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/xml
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE application/x-httpd-php
        AddOutputFilterByType DEFLATE application/x-httpd-fastphp
        AddOutputFilterByType DEFLATE application/x-httpd-eruby
        AddOutputFilterByType DEFLATE image/svg+xml
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE application/x-javascript

#What it should not compress
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary

#Maximum compression level (even old hardware have no problem with that...)
        DeflateCompressionLevel 9

#Handle browsers with known issues
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

#Logging
        DeflateFilterNote Input instream
        DeflateFilterNote Output outstream
        DeflateFilterNote Ratio ratio
        LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
</IfModule>



Restart apache

Code:
service httpd restart



Done !

_________________
Hello IT.
Phone : Blah Blah ....
Have you tried turning it on and off again ?
Phone : Blah Blah ....
....
I'm sorry, are you from the Past ?!
http://www.youtube.com/watch?v=-E4fm4Wqego


Top
 Profile  
 
 Post subject: Re: Apache Mod Deflate tutorial
Unread postPosted: Tue Apr 03, 2012 3:26 pm 
Offline
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
User avatar

Joined: Thu Feb 07, 2008 7:49 pm
Posts: 3549
Location: Chantilly, VA
Thanks for the great tutorial!

_________________
Michael Shinn
Atomicorp - Security For Everyone

Co-Author of Troubleshooting Linux Firewalls.


Top
 Profile  
 
 Post subject: Re: Apache Mod Deflate tutorial
Unread postPosted: Tue Apr 03, 2012 4:25 pm 
Offline
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin

Joined: Wed Dec 31, 1969 8:00 pm
Posts: 7780
Location: earth
Great work, we're trying all this out on the atomic servers right now


Top
 Profile  
 
 Post subject: Re: Apache Mod Deflate tutorial
Unread postPosted: Tue Apr 03, 2012 6:11 pm 
Offline
Forum Regular
Forum Regular

Joined: Sun Mar 29, 2009 6:52 pm
Posts: 350
You are welcome guys. You have helped me a million times. I am happy I was able to help once too :)

_________________
Hello IT.
Phone : Blah Blah ....
Have you tried turning it on and off again ?
Phone : Blah Blah ....
....
I'm sorry, are you from the Past ?!
http://www.youtube.com/watch?v=-E4fm4Wqego


Top
 Profile  
 
 Post subject: Re: Apache Mod Deflate tutorial
Unread postPosted: Tue Apr 03, 2012 6:59 pm 
Offline
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
User avatar

Joined: Thu Feb 07, 2008 7:49 pm
Posts: 3549
Location: Chantilly, VA
And if you want to test to see if your server is compressing content, you can use this site to do it:

http://www.whatsmyip.org/http-compression-test/

_________________
Michael Shinn
Atomicorp - Security For Everyone

Co-Author of Troubleshooting Linux Firewalls.


Top
 Profile  
 
 Post subject: Re: Apache Mod Deflate tutorial
Unread postPosted: Tue May 15, 2012 6:01 pm 
Offline
Forum Regular
Forum Regular

Joined: Sun Mar 29, 2009 6:52 pm
Posts: 350
scott wrote:
Great work, we're trying all this out on the atomic servers right now


Hey guys.
I didn't see any feedback so I wanted to ask. Did you see good results ? Maybe you did any configuration adjustments or added lines within the deflate.conf ?

_________________
Hello IT.
Phone : Blah Blah ....
Have you tried turning it on and off again ?
Phone : Blah Blah ....
....
I'm sorry, are you from the Past ?!
http://www.youtube.com/watch?v=-E4fm4Wqego


Top
 Profile  
 
 Post subject: Re: Apache Mod Deflate tutorial
Unread postPosted: Thu May 17, 2012 10:58 am 
Offline
Long Time Forum Regular
Long Time Forum Regular

Joined: Thu Dec 09, 2004 11:19 am
Posts: 2007
mod_deflate increases CPU usage -but it is always a good idea to use it even so. I've been using it for years. There are no downsides as such, as long as the config is good (and there are various ways of doing it -- I like the one here, which is similar to mine).

_________________
--------------------------------
<advert>
If you want to rent a UK-based VPS that comes with friendly advice and support from a fellow ART fan, please get in touch.
</advert>


Top
 Profile  
 
 Post subject: Re: Apache Mod Deflate tutorial
Unread postPosted: Thu May 17, 2012 11:29 am 
Offline
Forum Regular
Forum Regular

Joined: Mon Apr 14, 2008 8:29 am
Posts: 296
Location: Rhode Island
I started using it last month and as mentioned the cpu increase was up but it did make all the sites exspecially the joomla ones more snappy... :D


Top
 Profile  
 
 Post subject: Re: Apache Mod Deflate tutorial
Unread postPosted: Thu May 17, 2012 7:59 pm 
Offline
Forum Regular
Forum Regular

Joined: Sun Mar 29, 2009 6:52 pm
Posts: 350
Statistically the cpu goes up but only by an average of 2-3%.
With todays CPU's this increase is close to nothing. But on the other hand sites load faster and i think thats great.
Any suggestions for the conf though guys ? Maybe we can enhance this confguration more and make it even better !

_________________
Hello IT.
Phone : Blah Blah ....
Have you tried turning it on and off again ?
Phone : Blah Blah ....
....
I'm sorry, are you from the Past ?!
http://www.youtube.com/watch?v=-E4fm4Wqego


Top
 Profile  
 
 Post subject: Re: Apache Mod Deflate tutorial
Unread postPosted: Fri May 18, 2012 6:20 am 
Offline
Long Time Forum Regular
Long Time Forum Regular

Joined: Thu Dec 09, 2004 11:19 am
Posts: 2007
As I recall, there's two basic ways to set up mod_deflate:

Compress all by default, then define exceptions
Don't compress all by default, and define what to compress (with exceptions)

There's lots of things you don't want to compress:

Anything above a certain size, possibly (but I don't think this is an option in the config)

Every type of video file, possibly? (e.g. add .mkv in particular, plus possibly .ts, .mpg, .mpeg although some of those might benefit. But do we want to? They are likely to be big, and reducing a 10Mb file to 9Mb isn't worth my CPU cycles, I don't think.

What about Flash - .swf? .flv?

Audio files? .ogg, for example is nicely compressed to start with. But again some of those are compressible but may be big and not worth the bother.


Anyway here's an alternative mod_deflate.conf, which appears to be from the "deflate all, except as defined" school, and comes from the Apache website ( http://httpd.apache.org/docs/2.0/mod/mod_deflate.html ) with a modification to comment out the cludge for 2.0.48 on the assumption that people will be using a later version)

Code:
<Location />
 # 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 \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
 </Location>

_________________
--------------------------------
<advert>
If you want to rent a UK-based VPS that comes with friendly advice and support from a fellow ART fan, please get in touch.
</advert>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

» Feed - Atomicorp

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group