簡體   English   中英

背景圖片不顯示。 Rails 4,Nginx,美洲獅

[英]Background images don't show. Rails 4, nginx, puma

我按照http://ruby-journal.com/how-to-setup-rails-app-with-puma-and-nginx/的說明,使用puma和nginx設置rails(4.0.0)應用程序。 但是所有背景圖片和某些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;
  }
}

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

在將請求發送到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;
}  

嘗試這個:

RAILS_ENV=production bundle exec rake assets:precompile

暫無
暫無

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

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