背景图像不显示。 Rails 4,nginx,美洲狮

时间:2013-10-15 08:51:36

标签: ruby-on-rails image nginx assets puma

我正在使用puma和nginx设置rails(4.0.0)应用程序,然后执行此指令http://ruby-journal.com/how-to-setup-rails-app-with-puma-and-nginx/。但是所有背景图像和一些j都不起作用。

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;
  }
}

production.rb

     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

2 个答案:

答案 0 :(得分:1)

在将请求发送到Rails之前使用try_files检查静态文件

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;
}  

答案 1 :(得分:0)

试试这个:

RAILS_ENV=production bundle exec rake assets:precompile