Rails 3.1 Asset Pipeline 无法通过 nginx 反向代理工作
我正在将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你修改了你的开发环境文件吗?默认情况下,资产管道工作仅在生产中发生。
Did you modify your development environment file? By default the asset pipeline work is happening only in production.
您的问题很可能是您需要预编译资产。尝试运行
这是因为 nginx 只会盲目地尝试提供它应该提供的资源,这与 ruby 服务器不同,它会检查是否存在,如果不存在则进行编译。
我建议观看 Ryan Bates 的有关该主题的截屏视频。
编辑:
据我所知,如果文件不存在,就没有办法让 nginx 将请求传递到后端,但是我对配置 nginx 不太熟悉,所以这可能是一个很好的问题询问 ServerFault。
Your problem is most likely that you need to precompile the assets. Try running
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.