找不到Nginx + Rails 4资产 [英] Nginx + Rails 4 assets not found

查看:97
本文介绍了找不到Nginx + Rails 4资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将我的第一个Rails应用程序部署到了生产环境中,但是遇到了错误:nginx无法提供我的资产.资产已编译并存在.名称正确,路径正确. Nginx向我发送了404错误,而不是资产.作为服务器,如果需要的话,我会使用Puma.

I've just deployed my first Rails app to production, but encountered error: my assets for some reason are not served by nginx. Assets are compiled and exist. Names are correct, paths correct. Instead of assets nginx sends me 404 error. As a server I use Puma if that matters.

我对该部分的配置如下:

My config for that part looks like this:

  location ~* ^/assets/ {
    # Per RFC2616 - 1 year maximum expiry
    expires 1y;
    add_header Cache-Control public;

    # Some browsers still send conditional-GET requests if there's a
    # Last-Modified header or an ETag header even if they haven't
    # reached the expiry date sent in the Expires header.
    add_header Last-Modified "";
    add_header ETag "";
    break;
  }

推荐答案

我找到了问题的根源.我正在使用Capistrano进行部署,因此在我的Nginx配置中,我给出了错误的根路径

I've found the source of problems. I am using Capistrano for deploy, so in my nginx config I gave wrong root path

server {
  listen 80;
  server_name mydomain.com www.mydomain.com;
  root /var/www/my_portal/current/public;

我错过了根路径中的current部分,导致Capistrano将其链接到我的应用程序的当前版本.

I missed current part in the root path, cause Capistrano symlinked it to current release of my app.

这篇关于找不到Nginx + Rails 4资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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