Фоновые изображения не отображаются. Рельсы 4, nginx, пума

Я настраиваю приложение rails (4.0.0) с puma и nginx, следуя этой инструкции http://ruby-journal.com/how-to-setup-rails-app-with-puma-and-nginx/ . Но все фоновые изображения и некоторые js не работают.

my_app.conf

upstream my_app {
  server unix:///var/run/my_app.sock;
}

server {
  listen 80;
  server_name my_app_url.com; # change to match your URL
  root /var/www/my_app/public; # I assume your app is located at that location

  location / {
    proxy_pass http://my_app; # match the name of upstream directive which is defined above
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location ~* ^/assets/ {
    # Per RFC2616 - 1 year maximum expiry
    expires 1y;
    add_header Cache-Control public;

    # Some browsers still send conditional-GET requests if there's a
    # Last-Modified header or an ETag header even if they haven't
    # reached the expiry date sent in the Expires header.
    add_header Last-Modified "";
    add_header ETag "";
    break;
  }
}

производство.рб

     config.eager_load = true

  config.assets.precompile += Ckeditor.assets

  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  config.serve_static_assets = false

  config.assets.js_compressor = :uglifier

  config.assets.compile = true

  config.assets.digest = true

  config.assets.version = '1.0'

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

  config.log_level = :info

  # config.log_tags = [ :subdomain, :uuid ]

  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)


  # config.cache_store = :mem_cache_store

  # config.action_controller.asset_host = "http://assets.example.com"

  # config.assets.precompile += %w( search.js )

  # config.action_mailer.raise_delivery_errors = false

  config.i18n.fallbacks = true

  config.active_support.deprecation = :notify

  # config.autoflush_log = false

  config.log_formatter = ::Logger::Formatter.new

person Efremov    schedule 15.10.2013    source источник
comment
окружающая среда - это производство   -  person Efremov    schedule 15.10.2013
comment
Я думаю, что этот вопрос может быть связан с другим, который вы задали здесь: stackoverflow.com/questions/19388189/. Мой ответ исправил это?   -  person Aaron Gray    schedule 15.10.2013
comment
Да, Аарон, большое спасибо!   -  person Efremov    schedule 15.10.2013


Ответы (2)


Используйте try_files для проверки статических файлов перед отправкой запроса в Rails.

location / {
index index.html
try_files $uri $uri/ @ruby;
}

location @ruby {
  proxy_pass http://my_app; # match the name of upstream directive which is defined above
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}  
person zarazan    schedule 22.10.2013

Попробуй это:

RAILS_ENV=production bundle exec rake assets:precompile
person dax    schedule 15.10.2013
comment
Уже пробовал - не работает. Я не думаю, что это так, поскольку часть ресурсов (css, java, изображения) работает, только фоновые изображения не работают (ошибка 404) - person Efremov; 15.10.2013
comment
хм, какая версия рейлов? - person dax; 15.10.2013
comment
rails 4. UPD добавил production.rb - person Efremov; 15.10.2013