开发者

Rails 3.1 Asset Pipeline does not work through nginx reverse proxy

开发者 https://www.devze.com 2023-03-29 18:06 出处:网络
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.

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/applicatio开发者_运维百科n.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!


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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消