加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 为什么nginx找不到我的资产?

发布时间:2020-12-17 03:54:44 所属栏目:百科 来源:网络整理
导读:我在rails 3.2上,我的生产设置是使用nginx和unicorn. 我有一些资产,一个名为sidekiq的ruby宝石使用.但是,当我提出要求时,这些资产没有得到妥善处理.我的nginx配置看起来像这样: upstream unicorn { server unix:/tmp/unicorn.myapp.sock fail_timeout=0;}se
我在rails 3.2上,我的生产设置是使用nginx和unicorn.

我有一些资产,一个名为sidekiq的ruby宝石使用.但是,当我提出要求时,这些资产没有得到妥善处理.我的nginx配置看起来像这样:

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

server {
  listen 80 default deferred;
  # server_name example.com;
  root /home/deployer/apps/myapp/current/public;

  if (-f $document_root/system/maintenance.html) {
    return 503;my
  }
  error_page 503 @maintenance;
  location @maintenance {
    rewrite  ^(.*)$ /system/maintenance.html last;
    break;
  }

  location ~ ^/assets/ {
    gzip_static on;
    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;

  if (-f $document_root/system/maintenance.html) {
    return 503;
  }
  error_page 503 @maintenance;
  location @maintenance {
    rewrite  ^(.*)$ /system/maintenance.html last;
    break;
  }
}

从我的浏览器中我可以看到它是例如请求http://www.myapp.com/admin/sidekiq/stylesheets/application.css.

如果我ssh到服务器并写:

ls /home/deployer/apps/myapp/current/public/admin/sidekiq/stylesheets
application.css  bootstrap.css

你可以看到它确实在那里.那么为什么不服务呢?

解决方法

解决了它,这完全是由于我的production.rb中的错误设置导致默认行为失败,所以无论如何都不需要手动将资产放入/ public.

我有:

config.action_dispatch.x_sendfile_header = "X-Sendfile"

相反,nginx应该是:

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

感谢所有的帮助:-)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读