Heroku/Thin 上未提供静态资源

发布于 2024-11-28 12:32:15 字数 1452 浏览 0 评论 0原文

我遇到了 Heroku 上未提供静态资源(图像、js 和样式表)的问题。 在我的本地开发环境中运行良好。

错误看起来像这样:

2011-08-08T02:58:45+00:00 app[web.1]: Started GET "/stylesheets/reset.css" for 98.234.235.21 at 2011-08-07 19:58:45 -0700
2011-08-08T02:58:45+00:00 app[web.1]: 
2011-08-08T02:58:45+00:00 app[web.1]: ActionController::RoutingError (No route matches "/stylesheets/reset.css"):

我正在使用:

  • Ruby 1.9.2
  • Rails 3.0.7
  • Heroku 与bamboo-mri-1.9.2 和瘦网络服务器。 (我按照 heroku.com 上的默认基本设置说明进行操作)

我在 google / stackoverflow 上进行了搜索,并尝试了以下操作,但没有成功:

  • remove config.ru
  • add use ActionDispatch::Static, "#{Rails.root}/ public” 到 config.ru
  • 在 staging.rb 中设置 config.serve_static_assets = true

任何人都可以建议修复吗?我应该使用雪松而不是竹子吗?我应该使用其他东西来代替薄吗?

谢谢!


编辑: 正在提供 js 文件,但不提供图像和样式表。 我检查了链接中的路径是否一致。

myapp.heroku.com/stylesheets/reset.css - 失败 myapp.heroku.com/javascripts/jquery.js - 成功

我还尝试设置以下内容:config.action_dispatch.x_sendfile_header = nil。 这与 config.serve_static_assets = true 一致,但注意到 Heroku 会强制这些选项,无论您如何设置它们。即它在启动期间执行以下操作:

-----> Detected Rails is not set to serve static_assets
       Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile   
       Installing rails3_disable_x_sendfile... done

I'm having trouble with static assets (images and js and stylesheets) not being served on Heroku.
Works fine in my local dev env.

Errors look like this:

2011-08-08T02:58:45+00:00 app[web.1]: Started GET "/stylesheets/reset.css" for 98.234.235.21 at 2011-08-07 19:58:45 -0700
2011-08-08T02:58:45+00:00 app[web.1]: 
2011-08-08T02:58:45+00:00 app[web.1]: ActionController::RoutingError (No route matches "/stylesheets/reset.css"):

I'm using:

  • Ruby 1.9.2
  • Rails 3.0.7
  • Heroku with bamboo-mri-1.9.2 and thin webserver. (I followed default basic setup instructions on heroku.com)

I've searched on google / stackoverflow and tried the following with no luck:

  • remove config.ru
  • add use ActionDispatch::Static, "#{Rails.root}/public" to config.ru
  • set config.serve_static_assets = true in staging.rb

Can anyone suggest a fix? Should I be using Cedar instead of Bamboo? Should I be using something else instead of thin?

Thanks!


EDIT:
js files are being served, but images and stylesheets are not.
I checked that the paths in my links are consistent.

myapp.heroku.com/stylesheets/reset.css - fails
myapp.heroku.com/javascripts/jquery.js - succeeds

I also attempted to set the following: config.action_dispatch.x_sendfile_header = nil.
This goes along with config.serve_static_assets = true but noticed that Heroku forces these options no matter how you set them. i.e. it does the following during startup:

-----> Detected Rails is not set to serve static_assets
       Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile   
       Installing rails3_disable_x_sendfile... done

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恋竹姑娘 2024-12-05 12:32:15

问题结果是资产文件没有被推送到heroku(我遇到了git搞砸了,而不是heroku问题)。

当我联系 Heroku 支持人员时,他们指出了这一点。他们很快回复了详细的答案,其中还包括以下评论:

  • Heroku gem is not required to run on Heroku
  • 在 Gemfile 中指定 postgres gem;在本地使用 postgres 代替 sqlite3
  • config.ru 进行开发:不要直接运行调度程序,运行应用程序容器
  • 不要将 x_sendfile_header 设置为 nil,因为这在 Rails 3 上没有得到正确支持(这是 Rails 3.1 设置)

The problem turned out to be that the asset files didn't get pushed to heroku (I had a git screwup, not a heroku issue).

Heroku support pointed this out when I contacted them. They promptly replied with a detailed answer, which also included the following comments:

  • Heroku gem is not required to run on Heroku
  • Specify postgres gem in Gemfile; use postgres locally for development in place of sqlite3
  • config.ru: Don't run the dispatcher directly, run the app container
  • dont set x_sendfile_header to nil as this is not properly supported on Rails 3 (this is a Rails 3.1 setting)
不离久伴 2024-12-05 12:32:15

我不确定 Heroku 是否在 staging 环境中运行,我认为它是在 生产 环境中运行,这就是您的设置未被应用的原因。

I am not confident that Heroku is running in the staging environment, I think it's running in the production environment instead and this is why your settings are not being applied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文