Rgin资产未在Nginx + Passenger上加载

时间:2016-03-25 22:01:39

标签: ruby-on-rails-4 amazon-web-services nginx asset-pipeline passenger

我试图在Passenger + Nginx上设置Rails 4。我将我的应用程序部署到了Aws ubuntu。 我访问公共IP时加载了应用程序,但页面上没有CSS或图像。

以下是我的所作所为:

  • 在nginx site-enable config中:
server {
  listen 80 default_server;
  server_name my_ip_here;
  passenger_enabled on;
  rails_env production;
  root /path_to_public;
}

Application.scss

@import "bootstrap-sprockets";
@import "bootstrap";
@import "font-awesome";
@import "select2.min.css";
@import "toastr.css";
@import "magnific-popup.css";
@import "jgallery.css";
@import "rateit.css";
@import "load-awesome.css";
@import "dropzone.css";
@import "auto-complete.css";
@import "main.css";
@import "green.css";
@import "jquery.mCustomScrollbar.css";

production.rb

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Enable Rack::Cache to put a simple HTTP cache in front of your application
  # Add `rack-cache` to your Gemfile before enabling this.
  # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
  # config.action_dispatch.rack_cache = true

  # Disable Rails's static asset server (Apache or nginx will already do this).
  config.serve_static_files = false

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

  # Generate digests for assets URLs.
  config.assets.digest = true

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # 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

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # Set to :debug to see everything in the log.
  config.log_level = :info

  # Prepend all log lines with the following tags.
  # config.log_tags = [ :subdomain, :uuid ]

  # Use a different logger for distributed setups.
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = "http://assets.example.com"

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Disable automatic flushing of the log to improve performance.
  # config.autoflush_log = false

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false
end

之后我尝试运行bundle exec rake资产:预编译RAILS_ENV =生产但没有CSS和图像。

我在这个网站上阅读了几篇文章并试图将这一行添加到assets.rb中,但它会给我错误的未定义变量:" $ alert-padding"预编译资产时

config.assets.precompile = ['*.js', '*.css', '**/*.js', '*.scss']

我在日志中发现了这一点,但不确定它是否相关:

# current user is: ubuntu
# mkdir -p /usr/lib/buildout/ruby/ruby-2.2.1-x86_64-linux
Encountered permission error, trying a different directory...
-------------------------------
# mkdir -p /home/ubuntu/.passenger/native_support/5.0.26/ruby-2.2.1-x86_64-linux
# cd /home/ubuntu/.passenger/native_support/5.0.26/ruby-2.2.1-x86_64-linux
# /home/ubuntu/.rvm/gems/ruby-2.2.1/wrappers/ruby /usr/lib/src/ruby_native_extension/extconf.rb
ruby: No such file or directory -- /usr/lib/src/ruby_native_extension/extconf.rb (LoadError)

更新1:

我根据Rails文档更新了我的nginx配置文件

server {
  listen 80 default_server;
  server_name my_public_ip;
  passenger_enabled on;
  rails_env production;
  root /home/..../public;
  location ~ ^/assets/ {
    expires 1y;
    add_header Cache-Control public;

    add_header ETag "";
    break;
  }
}

0 个答案:

没有答案