预编译Nginx +独角兽后未加载Asset Rails 3.1 [英] assets rails 3.1 not load after precompile nginx + unicorn

查看:74
本文介绍了预编译Nginx +独角兽后未加载Asset Rails 3.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在生产环境中预编译资产.但是在预编译后,该应用程序找不到图像文件,javascripts文件,css文件...等.

I am trying precompile assets in production env. But after precompile the app does not find the images files, javascripts files, css files...etc.

我运行以下命令:

RAILS_ENV=production rake assets:precompile

我得到这个结果:

/home/hyperrjas/.rvm/rubies/ruby-1.9.2-p318/bin/ruby /home/hyperrjas/.rvm/gems/ruby-1.9.2-p318/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
/home/hyperrjas/.rvm/rubies/ruby-1.9.2-p318/bin/ruby /home/hyperrjas/.rvm/gems/ruby-1.9.2-p318/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets

然后我尝试重新加载页面,然后看到以下内容:

then I try reload the page and I see this:

我正在使用Nginx +独角兽.

I'm using nginx + unicorn.

为什么应用程序找不到资产,图像,CSS,JavaScript ...

我从 application.html.erb 加载我的资产布局:

I load my assets layout from application.html.erb with:

<%= stylesheet_link_tag    "application" %>
  <%= javascript_include_tag "application" %>

我在nginx.conf中的服务器{}中有此

I have in my nginx.conf this in server { }

location ~ ^/(assets)/  {
                          root ~/mydomain.com/current/public;
                          gzip_static on; # to serve pre-gzipped version
                          expires max;
                          add_header  Cache-Control public;
                         }

谢谢

推荐答案

问题已解决:D:

错误出在以下位置的nginx.conf中:

The error was in nginx.conf in:

location ~ ^/(assets)/  {
                         root ~/mydomain.com/current/public;
                         gzip_static on; # to serve pre-gzipped version
                         expires max;
                         add_header  Cache-Control public;
                        }

从根到资产的路径是错误的,正确的形式是:

The path to root to assets is bad, the correct form is:

 location ~ ^/(assets)/  {
                            root /home/hyperrjas/mydomain.com/current/public;
                            gzip_static on; # to serve pre-gzipped version
                            expires max;
                            add_header  Cache-Control public;
                           }

谢谢!

这篇关于预编译Nginx +独角兽后未加载Asset Rails 3.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆