1

我正在通过自定义域 www.shmocket.com 在 Heroku 上运行 Rails 3.2 应用程序。我使用 www.shmocket.com 作为唯一来源设置了 CloudFront 分配。它的备用域名是cdn.shmocket.com,它被简单地配置为 CloudFront 分配 URL 的 CNAME d3n87gn5nko8eq.cloudfront.net

当我通过 CloudFront 请求资产时,Rails 应用程序给我一个错误:

> curl http://cdn.shmocket.com/assets/application-dce210940d2cd3c699c4809800ae2f0b.css

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
  <HEAD><TITLE>Internal Server Error</TITLE></HEAD>
  <BODY>
    <H1>Internal Server Error</H1>
    undefined method `each' for nil:NilClass
    <HR>
    <ADDRESS>
     WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20) at
     www.shmocket.com:80
    </ADDRESS>
  </BODY>
</HTML>
curl: (18) transfer closed with 100318 bytes remaining to read

在 Rails 日志文件中:

2012-09-11T06:53:28+00:00 app[web.1]: [2012-09-11 06:53:28] ERROR NoMethodError: undefined method `each' for nil:NilClass
2012-09-11T06:53:28+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler/webrick.rb:71:in `service'
2012-09-11T06:53:28+00:00 app[web.1]:   /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
2012-09-11T06:53:28+00:00 app[web.1]:   /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
2012-09-11T06:53:28+00:00 app[web.1]:   /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
2012-09-11T06:53:28+00:00 heroku[router]: GET www.shmocket.com/assets/application-dce210940d2cd3c699c4809800ae2f0b.css dyno=web.1 queue=0 wait=0ms service=18ms status=500 bytes=325

直接访问http://www.shmocket.com/assets/application-dce210940d2cd3c699c4809800ae2f0b.css可以正常工作。

使用真正的CloudFront域时也会出现同样的错误,即http://d3n87gn5nko8eq.cloudfront.net/assets/application-dce210940d2cd3c699c4809800ae2f0b.css

CloudFront 配置:

http://screencast.com/t/A62AKBGX
http://screencast.com/t/u9Grgj5i
http://screencast.com/t/vzRduwxor50v

老实说,我很困惑,根本不知道是什么原因造成的。我怀疑我忽略了一些明显的东西......

任何建议表示赞赏...

编辑:

有人建议某些中间件对 CloudFront 发送的标头做出奇怪的反应。我没有手动包含任何中间件并检查了使用的宝石列表,我也看不到任何东西:

source :rubygems

ruby '1.9.3'

gem 'rails', '~> 3.2.8'
gem 'haml', '~> 3.2.0.beta.3'
gem 'jquery-rails', '2.0.2'
gem 'slim_migrations', '~> 3.2.1'
gem 'redis', '~> 2.2.2'
gem 'redis-rails', '~> 3.2.3'
gem 'memoizer', '~> 1.0.1'
gem 'marginalia', '~> 1.1.0'
gem 'awesome_print', '~> 1.0.2'
gem 'log_buddy', '~> 0.7.0'
gem 'squeel', '~> 1.0.9'
gem 'airbrake', '~> 3.1.2'
gem 'httparty', '~> 0.8.3'
gem 'ember-rails', '~> 0.7.0'

group :assets do
  gem 'oily_png', '~> 1.0.2'
  gem 'bootstrap-sass', github: 'dszczyt/bootstrap-sass'
  gem 'font_awesome', '~> 2.0.0'
  gem 'sass-rails', '~> 3.2.5'
  gem 'compass-rails', '~> 1.0.3'
  gem 'coffee-rails', '~> 3.2.2'
  gem 'uglifier', '~> 1.2.7'
end

group :development do
  gem 'heroku', '~> 2.30.5'
  gem 'annotate', '~> 2.5.0'
  gem 'foreman', '~> 0.57.0'
  gem 'quiet_assets', '~> 1.0.1'
  gem 'sextant', '~> 0.1.3'
  gem 'right_aws', '~> 3.0.4'
end

group :development, :test do
  gem 'mysql2', '~> 0.3.12b4'
end

group :production do
  gem 'pg', '~> 0.14.0'
end
4

1 回答 1

0

看起来这是一个带有 Heroku 的 Rack::Cache + Dalli gem
https://github.com/rails/rails/issues/8366的问题

禁用 Rack::Cache 从 production.rb 中加载解决了这个问题:

config.action_dispatch.rack_cache = nil
于 2013-05-12T06:50:45.467 回答