5

我正在构建一个 VPS,它通过 Capistrano、连接数据库等进行部署,但该页面没有可用的资产 - 它只是基本的 html。

资产似乎已编译,并存在于共享目录中。

从页面html:

<link href="/assets/application-a1b5d69aeaff709fd3dce163c559b38b.css" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/application-0ebd07089629f8c6880dddfb688d525d.js" type="text/javascript"></script>

资产文件似乎存在于共享目录中:

assay@assaypipeline:~/apps/assay/shared/assets$ ls application-  a1b5d69aeaff709fd3dce163c559b38b.css
application-a1b5d69aeaff709fd3dce163c559b38b.css

当我查看、来源然后单击资产路径的超链接时,我从 Nginx 中得到一个 404 未找到。

解决方案

感谢 Martin M(已接受的答案)的帮助。我从服务器上的 ~/apps/(app name)/current 目录中采取的步骤。

$ bundle install
$ RAILS_ENV=production bundle exec rake assets:precompile
$ sudo service nginx restart

显然,最好将其包含在 Capistrano 食谱中。

*编辑 - Capfile *

load 'deploy'
load 'deploy/assets'
load 'config/deploy'
4

2 回答 2

5

Your precompiled assets should reside in public/assets, see rails guides
normally you create them by running

RAILS_ENV=production bundle exec rake assets:precompile

as part of your deployment.
The shared stuff is to provide old stuff over several deploys.

See also this question

于 2013-07-18T10:14:46.550 回答
4

问题可能不在资产编译和部署中。尝试更改 nginx root /home/deploy/app_name/public; 到/home/deploy/app_name/current/public;在 nginx 配置文件 /etc/nginx/sites-enabled/default.

sudo nano /etc/nginx/sites-enabled/default

以下是我的配置文件

upstream app {
  # Path to Puma SOCK file, as defined previously
  server unix:/home/deploy/app_name/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
  listen 80;
  server_name localhost;

  root /home/deploy/app_name/current/public;

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

  location / {
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection '';
    proxy_pass http://app;
  }

  location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

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

希望这可以帮助

于 2016-10-05T13:28:18.593 回答