簡體   English   中英

為什么nginx找不到我的資產?

[英]Why can't nginx find my assets?

我在rails 3.2上,我的生產設置是使用nginx和unicorn。

我有一些資產,一個名為sidekiq的紅寶石寶石使用。 但是,當我提出要求時,這些資產沒有得到妥善處理。 我的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'

感謝所有的幫助:-)

對不起,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;

我將根據我們在日志中找到的內容修改我的答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM