ruby-on-rails – 资产不适用于RoR 4,Nginx,Unicorn

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 资产不适用于RoR 4,Nginx,Unicorn前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用Capistrano 2,Unicorn,Nginx部署了我的RoR 4应用程序.
问题是我获得404资产(样式表,javascripts).

这是Nginx访问日志:

89.0.40.233 - - [16/Mar/2014:08:24:26 +0000] "GET /stylesheets/application.css HTTP/1.1" 404 650 "http://host.cloudapp.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/33.0.1750.149 Safari/537.36"
89.0.40.233 - - [16/Mar/2014:08:24:26 +0000] "GET /javascripts/application.js HTTP/1.1" 404 650 "http://host.cloudapp.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/33.0.1750.149 Safari/537.36"

我的资源位于app文件夹中:

azureuser@host:~/apps/testify/current/public$ls -a assets
.                                                    application-d65a0eaefe6ca2eef9400045f94ab52b.js
..                                                   application-d65a0eaefe6ca2eef9400045f94ab52b.js.gz
application-71e2591e9586afebf3fb4ff70aaae199.css     manifest-a348973e84698f7d898e8021bd6e5388.json
application-71e2591e9586afebf3fb4ff70aaae199.css.gz

我的Nginx配置:

upstream unicorn {
  server unix:/tmp/unicorn.testify.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  root /home/azureuser/apps/testify/current/public;

  location ^~ /assets/ {
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @unicorn;

  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

我从哪里开始看?

解决方法

从access.log看来,你刚刚在你的布局中硬编码了application.css / .js.生产公用文件夹中没有此类文件,因为资产管道给出了它们的指纹名称(请查看示例ls输出).

你可能会读到这个here.

解决问题非常简单.使用以下代码替换application.css / .js的硬编码链接

<%= javascript_include_tag "application" %>
<%= stylesheet_link_tag "application" %>
原文链接:https://www.f2er.com/ruby/269180.html

猜你在找的Ruby相关文章