Nginx为什么找不到我的资产? [英] Why can't nginx find my assets?

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

问题描述

我处于3.2的轨道上,并且我的生产设置使用的是nginx和unicorn.

I'm on rails 3.2 and my production setup is using nginx and unicorn.

我对名为sidekiq的红宝石宝石使用的某些资产有疑问.但是,当我请求这些资产时,这些资产不能得到正确的服务.我的nginx配置看起来像这样:

I have a problem with some assets that a ruby gem called sidekiq uses. However those assets are not being served properly when I request them. My nginx config looks like this:

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.

From my browser I can see that it's
e.g. requesting http://www.myapp.com/admin/sidekiq/stylesheets/application.css.

如果我进入服务器并输入:

If I ssh into the server and write:

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

您可以看到它实际上在那里.那么为什么不提供它呢?

You can see that it's actually there. So why isn't it being served?.

推荐答案

已解决,这都是由于我在production.rb中的rails中的设置错误,导致默认行为失败,因此,无论如何都无需手动将资产放入/public.

Solved it, It was all due to a wrong setup in my production.rb in rails, which made the default behavior fail, so the hack of putting the assets into /public manually isn't necessary anyways.

我有:

config.action_dispatch.x_sendfile_header = "X-Sendfile"

nginx应该是:

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

感谢所有帮助:-)

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

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