Apache serving empty gzip with assets produced by Rails Asset Pipeline
- by PizzaPill
I followed the steps described on the blogpost The Asset Pipeline, from development to production and tweaked them to my environment. The two important files are:
/etc/apache/site-available/example.com
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "/var/www/sites/example.com/current/public"
    ErrorLog "/var/log/apache2/example.com-error_log"
    CustomLog "/var/log/apache2/example.com-access_log" common
    <Directory "/var/www/sites/example.com/current/public">
        Options All
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    <Directory "/var/www/sites/example.com/current/public/assets">
        AllowOverride All
    </Directory>
    <LocationMatch "^/assets/.*$">
        Header unset Last-Modified
        Header unset ETag
        FileETag none
        ExpiresActive On
        ExpiresDefault "access plus 1 year"
    </LocationMatch>
    RewriteEngine On
    # Remove the www
    RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
</VirtualHost>
/var/www/sites/example.com/shared/assets/.htaccess
RewriteEngine on
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]
<FilesMatch \.css\.gz$>
  ForceType text/css
  Header set Content-Encoding gzip
</FilesMatch>
<FilesMatch \.js\.gz$>
  ForceType text/javascript
  Header set Content-Encoding gzip
</FilesMatch>
But apache seems to send empty gzip files because the testsite looses all styles and firebug doesnt find any content for the css files. Altough if I call the assets-path directly I get some gibberish that looks like binary data.
If I move the htaccess-file everything is back to normal. How could I find out where/what went wrong or do you have any suggestions what error I made?
> apache2 -v
System: Server version: Apache/2.2.14 (Ubuntu)
Server built:   Mar  5 2012 16:42:17
> uname -a
Linux node0 2.6.18-028stab094.3 #1 SMP Thu Sep 22 12:47:37 MSD 2011 x86_64 GNU/Linux