• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

mod_deflate page compression

Phil Wareham

New Pleskian
Hi there, some of you might find this useful:

I have successfully enabled mod_deflate in Apache v2.x on my webserver and there do not seem to be any adverse affects on Plesk (so far!). For those who don't know mod_deflate compresses data before transmitting to compatible browsers, which then uncompress the data before displaying. On one of my site's homepage alone it saves 78% data bandwidth on a modern browser (Safari 3.1) so I'm pretty chuffed...

Original Size: 18 KB
Gzipped Size: 4 KB
Data Savings: 77.78%

Older browsers that do not support compressed data still get the uncompressed version so it is backwards compatible. You can test if your server already has mod_deflate enabled using the following tool...

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

If you have Apache 2.x on your server then chances are you already have mod_deflate installed but not enabled. You can check by opening your Apache httpd.conf file and do a search for "LoadModule deflate_module modules/mod_deflate.so"

If it is there but commented out (has a # at the start of the line) then uncomment it.

Then add the following code to the bottom of your httpd.conf file:

<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>

Restart Apache from the command line or within Plesk and all your hosted sites should now benefit.

Cheers,
Phil
 
Wouldn't it be better to include this in the /etc/httpd/conf.d/ instead of httpd.conf? Plesk upgrade might re-write these settings.

Rant: It also would be nice if Parallels would give us the option to enable this from the front-end. I'm a big fan of form follows function. In this case, since we're using a front-end to manage a server it would make more sense to have the feature added to the front-end instead of hacking it from the back. After all isn't the point of a control panel to ease the management?
 
cool, yes it works in the conf.d, creating a file called deflate.conf. Thanks!
 
Oh, did not realise Plesk can rewrite the httpd.conf file from time to time. Can you give me an idiots guide to using conf.d for this purpose instead as my Apache knowledge is pretty limited.
Thanks,
Phil
 
With Apache you can append additional directives, etc. to the original configuration. Sort of a in-line command per se. So instead of adding the mod_deflate syntax to httpd.conf directly, you create a file in conf.d named deflate.conf (just like bibliopegist did), and add your code there.

This is the same thing you would do if you want to setup open_base for your customers. Adding the configuration files for the additional directives to conf.d helps you compartmentalize things and keep your configuration clean.
 
One thing to keep in mind is that this can be a CPU hog.

Enabling it globally can therefore be a problem unless you have plenty of CPU power.

You can use something like this to only do it for one site (or multiple sites)

mod_deflate.conf (in /etc/httpd/conf.d)
*****************************

Code:
LoadModule deflate_module modules/mod_deflate.so
#above line does the loading of the .so so there's no need to have
# it in the potentially changing httpd.conf

<Directory /home/httpd/vhosts/[B]somdomain.tld[/B]/httpdocs/>
  <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>
</Directory>
*************************
 
OK thanks all, now have a deflate.conf file as recommended. My server only hosts a couple of high-traffic sites so the CPU usage is well under control for the moment.
Cheers,
Phil
 
Back
Top