2017-03-08 16 views
0

早些時候,我使用乘客和獨角獸與capistrano和nginx部署了相同的源代碼。那裏工作正常。但現在我正在嘗試使用Puma服務器來做同樣的事情。資產根本沒有加載。使用puma部署的Rails 4.2.6應用程序不會加載資產和圖像。

環境/ 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 


    config.eager_load = true 

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


    config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 

    config.assets.js_compressor = :uglifier 

    config.assets.compile = true 

    config.assets.digest = true 



    # config.force_ssl = true 

    # Use the lowest log level to ensure availability of diagnostic information 
    # when problems arise. 
    config.log_level = :debug 

    config.action_mailer.default_url_options = { host: ENV["SMTP_HOST"] } 
    config.action_mailer.asset_host = ENV["SMTP_HOST"] 
    # config.action_mailer.delivery_method = :letter_opener 
    config.action_mailer.raise_delivery_errors = false 

    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
    #Enter the smtp provider here ex: smtp.mandrillapp.com 
    address: ENV["SMTP_ADDRESS"], 
    port: ENV['SMTP_PORT'].to_i, 
    #Enter the smtp domain here ex: xxx.com 
    domain: ENV["SMTP_DOMAIN"], 
    #Enter the user name for smtp provider here 
    user_name: ENV["SMTP_USERNAME"], 
    #Enter the password for smtp provider here 
    password: ENV["SMTP_PASSWORD"], 
    authentication: 'plain', 
    enable_starttls_auto: true 
    } 

    config.i18n.fallbacks = true 

    config.active_support.deprecation = :notify 

    config.log_formatter = ::Logger::Formatter.new 

    config.active_record.dump_schema_after_migration = false 
end 

capfile

# Load DSL and set up stages 
require "capistrano/setup" 

# Include default deployment tasks 
require "capistrano/deploy" 

# Load the SCM plugin appropriate to your project: 
# 
# require "capistrano/scm/hg" 
# install_plugin Capistrano::SCM::Hg 
# or 
# require "capistrano/scm/svn" 
# install_plugin Capistrano::SCM::Svn 
# or 
require "capistrano/scm/git" 
install_plugin Capistrano::SCM::Git 

require 'capistrano/rails' 
#require 'capistrano/passenger' 

# If you are using rvm add these lines: 
require 'capistrano/rvm' 
set :rvm_type, :user 
set :rvm_ruby_version, '2.2.4' 

# Include tasks from other gems included in your Gemfile 
# 
# For documentation on these, see for example: 
# 
# https://github.com/capistrano/rvm 
# https://github.com/capistrano/rbenv 
# https://github.com/capistrano/chruby 
# https://github.com/capistrano/bundler 
# https://github.com/capistrano/rails 
# https://github.com/capistrano/passenger 
# 
require "capistrano/rvm" 
# require "capistrano/rbenv" 
# require "capistrano/chruby" 
require "capistrano/bundler" 
require "capistrano/rails/assets" 
require "capistrano/rails/migrations" 
# require "capistrano/passenger" 
require 'capistrano/puma' 

# Load custom tasks from `lib/capistrano/tasks` if you have any defined 
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } 

回答

1

您可以檢查您Nginx config file它是否允許資產(圖片,字體等)爲您的應用程序或沒有。

location ^~ /(assets|fonts|swfs|images)/ { 
    gzip_static on; 
    expires max; 
    add_header Cache-Control public; 
    } 

希望這會幫助你。

0

如果你已經沒有,加入rails_12factor寶石解決這種類似的問題,對我來說

希望它有幫助。

gem 'rails_12factor', group: :production 

- 更新 -

也有重複,需要在你的capfile。以下是Capfile的乾淨版本。您需要將rvm設置移至deploy.rb。你並不需要使用捆綁,資產和遷移如果你是包括Capistrano的/導軌

# Load DSL and set up stages 
require "capistrano/setup" 

# Include default deployment tasks 
require "capistrano/deploy" 

# Load the SCM plugin appropriate to your project: 
# 
# require "capistrano/scm/hg" 
# install_plugin Capistrano::SCM::Hg 
# or 
# require "capistrano/scm/svn" 
# install_plugin Capistrano::SCM::Svn 
# or 
require "capistrano/scm/git" 
install_plugin Capistrano::SCM::Git 

# Include tasks from other gems included in your Gemfile 
# 
# For documentation on these, see for example: 
# 
# https://github.com/capistrano/rvm 
# https://github.com/capistrano/rbenv 
# https://github.com/capistrano/chruby 
# https://github.com/capistrano/bundler 
# https://github.com/capistrano/rails 
# https://github.com/capistrano/passenger 
# 
require 'capistrano/rvm' 
require 'capistrano/rails' 
require 'capistrano/puma' 
# require "capistrano/rvm" 
# require "capistrano/rbenv" 
# require "capistrano/chruby" 
# require "capistrano/bundler" 
# require "capistrano/rails/assets" 
# require "capistrano/rails/migrations" 
# require "capistrano/passenger" 

# Load custom tasks from `lib/capistrano/tasks` if you have any defined 
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } 
+0

我將它添加到gem文件中。部署它。重新啓動服務器。但仍然沒有加載資產 – user3576036

+0

編譯後的資產是否以不同的名稱存在或者甚至沒有被編譯?您應該能夠在部署期間在capistrano輸出中看到它 –

相關問題