1

I have apache 2.2.22 running on debian.

I have tried to enable deflate on this server but no matter what I do, the response is not getting deflated.

Here is the list of enabled modules:

apache2ctl -M
Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 alias_module (shared)
 auth_basic_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 expires_module (shared)
 filter_module (shared)
 headers_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 pagespeed_module (shared)
 php5_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)
Syntax OK

Here is my Virtual Host:

<VirtualHost 148.251.236.145:80>

  ServerName                    www.tren.at
  ServerAlias                   tren.at *.tren.at
  ServerAdmin                   webmaster@tren.at
  DocumentRoot                  /var/www/tren
  ServerSignature               on
  LogLevel                      info
  ErrorLog                      /var/log/apache2/error-tren.log
  CustomLog                     /var/log/apache2/access-tren.log combined
  RewriteLog            /var/log/apache2/rewrite-tren.log
  RewriteLogLevel       3
  AllowEncodedSlashes       on

 <Directory /var/www/tren/>
  Options                       Indexes FollowSymLinks MultiViews
  AllowOverride                 all
  Order                         allow,deny
  Allow from                    all
  DirectoryIndex                index.php
 </Directory>

 <Directory /var/www/tren/images/>
  <FilesMatch "(?i)\.((?!.*(jpg|jpeg|png|gif|bmp)).*)$">
    Order Deny,Allow
    Deny from All
  </FilesMatch>
 </Directory>

 <Directory /var/www/tren/cache/>
  <FilesMatch "(?i)\.((?!.*(jpg|jpeg|png|gif|bmp)).*)$">
    Order Deny,Allow
    Deny from All
  </FilesMatch>
 </Directory>

</VirtualHost>

And finally here is my .htaccess

Options -MultiViews
Options +FollowSymLinks

# Enable GZIP
<IfModule mod_deflate.c>
  # HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
  <IfModule filter_module>
    FilterDeclare   COMPRESS
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/html
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/css
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/plain
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/x-component
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/javascript
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/json
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xhtml+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/rss+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/atom+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/vnd.ms-fontobject
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $image/svg+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/x-font-ttf
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $font/opentype
    FilterChain     COMPRESS
    FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
  </IfModule>

  <IfModule !mod_filter.c>
    # Legacy versions of Apache
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
    AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml 
    AddOutputFilterByType DEFLATE application/atom+xml
    AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject 
    AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype
  </IfModule>
</IfModule>

# Expires Headers - 2678400s = 31 days
<ifmodule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 7200 seconds"
  ExpiresByType image/gif "access plus 2678400 seconds"
  ExpiresByType image/jpeg "access plus 2678400 seconds"
  ExpiresByType image/png "access plus 2678400 seconds"
  ExpiresByType text/css "access plus 518400 seconds"
  ExpiresByType text/javascript "access plus 2678400 seconds"
  ExpiresByType application/x-javascript "access plus 2678400 seconds"
</ifmodule>

# Cache Headers
<ifmodule mod_headers.c>
  # Cache specified files for 31 days
  <filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
  Header set Cache-Control "max-age=2678400, public"
  </filesmatch>
  # Cache HTML files for a couple hours
  <filesmatch "\.(html|htm)$">
  Header set Cache-Control "max-age=7200, private, must-revalidate"
  </filesmatch>
  # Cache PDFs for a day
  <filesmatch "\.(pdf)$">
  Header set Cache-Control "max-age=86400, public"
  </filesmatch>
  # Cache Javascripts for 31 days
  <filesmatch "\.(js)$">
  Header set Cache-Control "max-age=2678400, private"
  </filesmatch>
</ifmodule>

RewriteEngine on

RewriteBase /

RewriteRule . - [E=no-gzip:1]

RewriteRule ^(.*)/product/([0-9]+)/(.*)$ product_info.php/products_id/$2/$3 [QSA,L]

RewriteRule ^(.*)/product/([0-9]+)$ product_info.php?products_id=$2 [QSA,L]

RewriteRule ^(.*)/cat/([0-9,_]+)/(.*)$ index.php/cPath/$2/$3 [QSA,L]

RewriteRule ^(.*)/cat/([0-9,_]+)$ index.php?cPath=$2 [QSA,L]


## Redirect to www
#
RewriteCond %{http_host} ^tren.at [nc]

RewriteRule ^(.*)$ http://www.tren.at/$1 [r=301,nc]

If I now try to get a simple html file from the site, it is not being compressed. The same happens with php output:

curl --compressed -I http://www.tren.at/test.html
HTTP/1.1 200 OK
Date: Wed, 22 Apr 2015 10:37:57 GMT
Server: Apache/2.2.22 (Debian)
Last-Modified: Wed, 12 Nov 2014 10:34:38 GMT
Accept-Ranges: none
Cache-Control: max-age=7200, private, must-revalidate
Expires: Wed, 22 Apr 2015 12:37:57 GMT
Content-Length: 322
Content-Type: text/html

I already disabled output_buffering and zlib.output_compression in php.ini.

Is there an error somewhere in my configuration? What else can I try to find the problem/fix the issue?

EDIT:

Interestingly enough, when I made syntax error in my configuration, the 500 error I got was gzipped!

3

I have the following, which works, and looks quite different to yours. What if you simplify your config to be roughly this?

SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript

Also, don't forget to use Vary: Accept-Encoding and not Vary: User-Agent if you can avoid doing so. You might also like to adjust the incoming Accept-Encoding request headers before they hit your cache (if you have one). Otherwise, you'd get really rubbish cache-hit rates because you'd be caching 40+ different representations for all the different compression techniques and all the different user-agent strings.

Here is what I would put on a reverse-proxy to implement this.

# Edit incoming request header Accept-Encoding in order
# to get greater cache utilisation and less disk utilisation. Otherwise we
# end up with a lot of (potentially different) encodings; one for each unique
# Accept-Encoding header... there would be over 50; including very unusual
# ones.
#
# This pair of regular expressions implements a two-part transform which:
#  1) for any Accept-Encoding header which has gzip, makes it the only value,
#     plus adds a dummy value to remind log-observers that it has been edited.
#  2) then, it will replace any Accept-Encoding that did not mention gzip,
#     clears it out. mod_deflate only supports gzip anyway (despite the name)
#
# I was afraid that this would have to run as an 'early' handler, and perhaps
# on older versions of Apache 2.2, perhaps that would be the case; but at least
# for httpd-2.2.3-91.el5 on RHEL 5, this is not the case. I think there was
# some talk of making the caching not and early module... but I believe the
# documentation still refers to it as an early module.
#
RequestHeader edit Accept-Encoding "^(?:.*,?\s*)?\b(gzip)\b(?:,.*)?$" "$1, MASHED"
RequestHeader edit Accept-Encoding "^(?!.*\bgzip\b.*).*$" "$1"

The MASHED is largely for my benefit as a reminder that the header has been edited.

  • That simple configuration was the first thing I tried. Only after hours of research did I set up the complicated version you see in my question. However, I tried it once more just to be sure, but without success. – Bojan Hrnkas Apr 22 '15 at 11:43
  • Perhaps your problem that you're trying to do something in a htaccess file that should perhaps be done in the server config. – Cameron Kerr Apr 22 '15 at 11:45
  • I tried putting the same configuration in my Virtual Host. No change. Is there some Log I could check? I tried building my own log using code found here: pontikis.net/blog/speed-up-your-website-with-gzip-compression. Output was only "-" instead of the numbers. – Bojan Hrnkas Apr 22 '15 at 12:05
0

The culprit was a rule in the rewrite mod:

RewriteRule . - [E=no-gzip:1]

This was part of the old configuration that I forgot about.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.