我假定你的意思我如何爲我的靜態資產從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做一個不敏感的reg-ex比較。您也不需要像在其他語言中那樣避開反斜槓。
以下是關於此的Nginx文檔:http://wiki.nginx.org/HttpCoreModule#location