4

私は Rails 3.2 を使用しており、本番環境では nginx と unicorn を使用しています。

sidekiq と呼ばれる ruby​​ gem が使用するいくつかのアセットに問題があります。しかし、これらのアセットはリクエストしても適切に提供されません。私の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;
  }
}

私のブラウザから、
たとえば requestingであることがわかりhttp://www.myapp.com/admin/sidekiq/stylesheets/application.cssます。

サーバーにsshして次のように書くと:

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

実際にあることがわかります。では、なぜ提供されていないのでしょうか。

4

2 に答える 2

9

解決しました。レールの production.rb の設定が間違っていたため、デフォルトの動作が失敗したため、アセットを /public に手動で配置するハックはとにかく必要ありません。

私が持っていた:

config.action_dispatch.x_sendfile_header = "X-Sendfile"

代わりに、nginx の場合は次のようになります。

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

すべての助けをありがとう:-)

于 2012-12-19T15:19:09.737 に答える
1

すみません、Niels、あなたを助けるためにもっと情報が必要になると思います。ログを有効にしてから、ログに記録された回答を質問に投稿してください。

ロギングを有効にするには、構成に次の行を含めてから、構成をリロードするか、NginX を再起動してください。

    log_format my_log_format
        '$host $remote_addr - $remote_user [$time_local]  $status '
        '"$request" $body_bytes_sent "$http_referer" '
        '"$http_user_agent" "$http_x_forwarded_for"';

    error_log  /home/deployer/myapp_error.log;
    access_log /home/deployer/myapp_access.log my_log_format;

ログで見つかった内容に従って、回答を修正します。

于 2012-12-19T14:25:53.890 に答える