0

I have an inherited Apache 2.2.17 server running on Ubuntu that I need to enable compression on. I have ensured the mod is loaded:

apachectl -t -D DUMP_MODULES
Loaded Modules:
...
deflate_module (shared)
headers_module (shared)
setenvif_module (shared)
...

I have then set http.conf with the following rules:

<IfModule deflate_module>
    SetOutputFilter DEFLATE

        <IfModule setenvif_module>
        # 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 (comment the above line and uncomment the below line) to get the desired effect:
        # BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

        # Don’t compress already-compressed files
        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 .(?:avi|mov|mp3|mp4|rm|flv|swf|mp?g)$ no-gzip dont-vary
        SetEnvIfNoCase Request_URI .pdf$ no-gzip dont-vary
    </IfModule>

    <IfModule headers_module>
        # Make sure proxies don’t deliver the wrong content
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
</IfModule>

Now if I retrieve the HEAD using python or curl I get a gzip response (this is just for a .txt file but is consistent accross the site):

Date: Mon, 06 May 2013 11:53:31 GMT
Server: Apache/2.2.17 (Ubuntu)
Last-Modified: Sun, 05 May 2013 12:37:23 GMT
ETag: "2412002-129c6-4dbf7d88766c0"
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Content-Length: 32607
Content-Type: text/plain

However if I do a POST or GET, I do not get gzip back:

Date: Mon, 06 May 2013 11:53:25 GMT
Server: Apache/2.2.17 (Ubuntu)
Last-Modified: Sun, 05 May 2013 12:37:23 GMT
ETag: "2412002-129c6-4dbf7d88766c0"
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Content-Type: text/plain
Content-Length: 76230

UPDATE: Here are the headers from Firefox 20. Firebug & Google confirm gzip is being requested:

Date: Tue, 07 May 2013 16:57:01 GMT
Server: Apache/2.2.17 (Ubuntu)
X-Powered-By: PHP/5.3.5-1ubuntu7.10
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding,User-Agent
Keep-Alive: timeout=15, max=98
Connection: Keep-Alive
Content-Type: text/html
Content-Length: 19922

This has been frustrating me for a few days now and any help would be much appreciated.

Thanks

3
  • Have you tried inspecting response headers from a real browser request? Curl do not send default headers that real browsers send.
    – Marcel
    May 7, 2013 at 11:30
  • Hi @Marcel, have added the information from Firefox 20. Chrome with yslow also reports the site as not sending gzip.
    – Naozumi
    May 7, 2013 at 17:02
  • 1
    gzip and deflate are two different compression methods. I think mod_deflate can do both, but they're not the same...
    – Chris S
    May 7, 2013 at 17:12

1 Answer 1

0

As it turned out, the config wasn't really being run very well, and the site always chose deflate over gzip. As such I wasn't seeing it working. I simplified my http.conf, and enabled a log on linux which showed that it was infact working:

LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so

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

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

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/apache2/deflate_log deflate

The last section wrote a log that showed that some content is infact compressing. Some of it still does not but I believe this now to be down to the way the php runs. I am going to look into also using php compression to handle that better.

And thanks Marcel & Chris S for helping me figure this out.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .