ユニコーンではなくnginxから静的アセットを提供するにはどうすればよいですか
私はちょうどこの問題を解決しました。ここに私のスニペットがありますnginx.conf
# Prefer to serve static files directly from nginx to avoid unnecessary
# data copies from the application server.
try_files $uri/index.html $uri.html $uri @app;
# Set Far Future Cache on Static Assets
# All requests starting with /xyz/ where xyz is
# one of the options below (~* == case insensitive)
location ~* ^/(images|javascripts|stylesheets)/ {
# Per RFC2616 - 1 year maximum expiry
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
expires 1y;
add_header Cache-Control public;
# 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.
add_header Last-Modified "";
add_header ETag "";
break;
}
location @app { ... }
私はRails 3.0.10を使用しているので、^/assets/代わりに次のようなものが必要です。この~*ディレクティブは、nginx に大文字と小文字を区別しない正規表現の比較を行うように指示します。また、他の言語のようにバックスラッシュをエスケープする必要はありません。
これに関するNginxのドキュメントは次のとおりです。 http://wiki.nginx.org/HttpCoreModule#location