Rails 3.1 Asset Pipeline 无法通过 nginx 反向代理工作

发布于 2024-12-01 06:22:43 字数 966 浏览 0 评论 0原文

我正在将 Rails 3.0 应用程序升级到 Rails 3.1,但资产管道在开发中无法正常工作。我正在使用 Thin 和 nginx 反向代理。

例如

javascript_include_tag 'application' # => <script src="/javascripts/application.js" type="text/javascript"></script>

,使用curl...

$ curl -sL -w "%{http_code}" "http://myapp.dev/javascripts/application.js" -o /dev/null
404
$ curl -sL -w "%{http_code}" "http://myapp.dev/assets/application.js" -o /dev/null
404

但是当我直接打thin而不是通过nginx时,我得到了我所期望的:

javascript_include_tag 'application' # => <script src="/assets/application.js" type="text/javascript"></script>

它有效吗?

$ curl -sL -w "%{http_code}" "http://localhost:3000/assets/application.js" -o /dev/null
200

是的!为什么会出现这种情况呢?

以下是我的 nginx 配置摘录: https://gist.github.com/1163638

很高兴提供更多信息,请询问!

I am upgrading a Rails 3.0 application to Rails 3.1, and the asset pipeline is not working in development. I am using thin with an nginx reverse proxy.

For example

javascript_include_tag 'application' # => <script src="/javascripts/application.js" type="text/javascript"></script>

And with curl...

$ curl -sL -w "%{http_code}" "http://myapp.dev/javascripts/application.js" -o /dev/null
404
$ curl -sL -w "%{http_code}" "http://myapp.dev/assets/application.js" -o /dev/null
404

But when I hit thin directly instead of through nginx, I get what I would expect:

javascript_include_tag 'application' # => <script src="/assets/application.js" type="text/javascript"></script>

Does it work?

$ curl -sL -w "%{http_code}" "http://localhost:3000/assets/application.js" -o /dev/null
200

Yep! Why might this be the case?

Here is an excerpt from my nginx configuration: https://gist.github.com/1163638

Happy to provide more information, just ask!

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

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

发布评论

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

评论(2

紧拥背影 2024-12-08 06:22:43

你修改了你的开发环境文件吗?默认情况下,资产管道工作仅在生产中发生。

Did you modify your development environment file? By default the asset pipeline work is happening only in production.

梦萦几度 2024-12-08 06:22:43

您的问题很可能是您需要预编译资产。尝试运行

rake assets:precompile

这是因为 nginx 只会盲目地尝试提供它应该提供的资源,这与 ruby​​ 服务器不同,它会检查是否存在,如果不存在则进行编译。

我建议观看 Ryan Bates 的有关该主题的截屏视频

编辑:

据我所知,如果文件不存在,就没有办法让 nginx 将请求传递到后端,但是我对配置 nginx 不太熟悉,所以这可能是一个很好的问题询问 ServerFault

Your problem is most likely that you need to precompile the assets. Try running

rake assets:precompile

This is due to the fact that nginx will just blindly try to serve the assets that it is supposed to, unlike a ruby server, which will check for existence, and compile if they don't exist.

I would suggest watching Ryan Bates' screencast on the subject.

Edit:

As far as I know, there is no way to make nginx pass the request off to the backend if the file doesn't exist, however I'm not very familiar with configuring nginx, so that would probably be a good question to ask on ServerFault.

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