Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 未在Nginx+上加载Rails资产;乘客_Ruby On Rails 4_Amazon Web Services_Nginx_Asset Pipeline_Passenger - Fatal编程技术网

Ruby on rails 4 未在Nginx+上加载Rails资产;乘客

Ruby on rails 4 未在Nginx+上加载Rails资产;乘客,ruby-on-rails-4,amazon-web-services,nginx,asset-pipeline,passenger,Ruby On Rails 4,Amazon Web Services,Nginx,Asset Pipeline,Passenger,我正在尝试在乘客+Nginx上设置Rails 4。我将我的应用程序部署到Aws ubuntu。 当我访问公共IP时会加载应用程序,但页面上没有CSS或图像 以下是我所做的: 在nginx中,站点启用配置: Application.scss @import "bootstrap-sprockets"; @import "bootstrap"; @import "font-awesome"; @import "select2.min.css"; @import "toastr.css"; @im

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

以下是我所做的:

  • 在nginx中,站点启用配置:
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资产:precompile RAILS_ENV=production,但仍然没有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;
  }
}

对于加载失败的文件,浏览器控制台中是否有错误消息?加载失败资源:对于在application.css.scss中导入的所有文件,服务器以404(未找到)的状态响应。您确定浏览器正在同一IP上查找访问应用程序的文件吗?
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;
  }
}