【发布时间】:2016-04-12 07:35:39
【问题描述】:
Given: 64bit Amazon Linux 2015.09 v2.0.4 running Ruby 2.2 (Passenger Standalone) behind ELB. Rails 4.25 in production with default asset pipeline settings.
我注意到没有为静态资产(css、js)设置缓存控制标头。我期待类似的东西
public, max-age=31557600
或类似的,而不是我得到以下内容:
> curl -I http://xxx.elasticbeanstalk.com/assets/application-7e1554f74fd0352dbb5ccdbba5d50d1c1f28a4ca751e9ec8371bd55e28885f77.css
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 16557
Content-Type: text/css
Date: Tue, 05 Jan 2016 21:16:53 GMT
ETag: "568bde8a-40ad"
Last-Modified: Tue, 05 Jan 2016 15:17:30 GMT
Server: nginx/1.6.2
Connection: keep-alive
在 Rails 中设置标题并指示它通过应用程序提供资产,例如
# production.rb
config.static_cache_control = "public, max-age=#{1.year.to_i}"
config.serve_static_files = true
没有任何区别,资产仍然由 nginx 提供服务。
在/tmp/passenger-standalone.1d76nuz/config(虽然不确定这是否是活动配置)我看到以下内容:
server {
...
# Rails asset pipeline support.
location ~ "^/assets/.+-[0-9a-f]{32}\..+" {
error_page 490 = @static_asset;
error_page 491 = @dynamic_request;
recursive_error_pages on;
if (-f $request_filename) {
return 490;
}
if (!-f $request_filename) {
return 491;
}
}
location @static_asset {
gzip_static on;
expires max;
add_header Cache-Control public;
add_header ETag "";
}
location @dynamic_request {
passenger_enabled on;
}
}
不胜感激任何建议。我正在尝试利用 CloudFront 来提供资产,但如果没有适当的缓存控制标头,效率会低很多。
谢谢! 2016 年快乐!
【问题讨论】:
标签: ruby-on-rails nginx passenger amazon-elastic-beanstalk cache-control