1

この指示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
4

2 に答える 2

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;
}  
于 2013-10-22T19:08:26.230 に答える
0

これを試して:

RAILS_ENV=production bundle exec rake assets:precompile
于 2013-10-15T13:19:09.237 に答える