我按照博客文章中描述的步骤进行操作从开发到生产的资产管道并根据我的环境对其进行了调整。两个重要的文件是:
/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>
但是 apache 似乎发送了空的 gzip 文件,因为测试站点丢失了所有样式,并且 firebug 找不到 css 文件的任何内容。尽管如果我直接调用 assets-path,我得到的是一些看起来像二进制数据的乱码。如果我移动 htaccess 文件,一切都会恢复正常。我怎么才能找出哪里出了问题,或者你对我犯了什么错误有什么建议吗?
> 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