简体   繁体   English

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

[英]Rails 3.1 Asset Pipeline does not work through nginx reverse proxy

I am upgrading a Rails 3.0 application to Rails 3.1, and the asset pipeline is not working in development. 我正在将Rails 3.0应用程序升级到Rails 3.1,并且资产管道在开发中不起作用。 I am using thin with an nginx reverse proxy. 我使用nginx反向代理瘦。

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: 但是当我直接点击瘦而不是通过nginx时,我得到了我期望的结果:

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 以下是我的nginx配置的摘录: https//gist.github.com/1163638

Happy to provide more information, just ask! 很高兴提供更多信息,请问!

Did you modify your development environment file? 您是否修改了开发环境文件? By default the asset pipeline work is happening only in production. 默认情况下,资产管道工作仅在生产中发生。

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. 这是因为nginx会盲目地尝试为它应该提供的资产服务,不像ruby服务器会检查是否存在,如果它们不存在则编译。

I would suggest watching Ryan Bates' screencast on the subject . 我建议观看Ryan Bates 关于这个主题截屏

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 . 据我所知,如果文件不存在,没有办法让nginx将请求传递给后端,但是我对配置nginx并不是很熟悉,所以这可能是一个很好的问题。 ServerFault

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM