Passenger で Rails アプリを動かすときに、assets:precompile 済みの gz ファイルを返すようにする apache の設定方法例のメモ。

いただき物です。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<VirtualHost *:80>
   # ...
   <LocationMatch "^/assets/.*$">
     # Some browsers still send conditional-GET requests if there's a
     # Last-Modified header or an ETag header even if they haven't
     # reached the expiry date sent in the Expires header.
     #Header unset Last-Modified
     #Header unset ETag
     FileETag Size
     # RFC says only cache for 1 year
     ExpiresActive On
     ExpiresDefault "access plus 1 year"

     SetEnv no-gzip

     RewriteEngine on
     #RewriteLog /tmp/rewrite.log
     #RewriteLogLevel 15
     # Make sure the browser supports gzip encoding before we send it
     RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
     RewriteCond %{REQUEST_FILENAME}.gz -f
     RewriteRule ^(.+) \$1.gz [L]
   </LocationMatch>

   <FilesMatch \.css\.gz$>
       ForceType text/css
       Header set Content-Encoding gzip
   </FilesMatch>

   <FilesMatch \.js\.gz$>
       ForceType text/javascript
       Header set Content-Encoding gzip
   </FilesMatch>
</VirtualHost>