2016-03-05 73 views
0

更改css文件后,我做了一个rake资源:预编译并将其推送到git。然后对我的服务器做了一次capistrano的新部署。现在我的资产或样式都没有显示在我的页面http://162.243.102.157/上。
这些资产位于生产部署服务器上,但我似乎无法弄清楚为什么乘客或Rails未提供服务并将资产显示到我的网站......?Rails Passenger/Capistrano/Ubuntu应用程序未提供资产

我的红宝石-v是:
2.2.3p173

的Rails -v:
4.2.5.2

capfile:

# Load DSL and set up stages 
require 'capistrano/setup' 
# Include default deployment tasks 
require 'capistrano/deploy' 
# 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 
# If you are using rbenv add these lines: 
require 'capistrano/rbenv' 
set :rbenv_type, :user # or :system, depends on your rbenv setup 
set :rbenv_ruby, '2.2.3' 
require 'capistrano/bundler' 
require 'capistrano/rails' 
require 'capistrano/setup' 
#require 'capistrano/deploy' 
# require 'capistrano/rvm' 
require 'capistrano/rbenv' 
# require 'capistrano/chruby' 
#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 } 

的Gemfile:

source 'https://rubygems.org' 
ruby '2.2.3' 

gem 'rake', '~> 10.5' 

gem 'rails', '~> 4.2', '>= 4.2.5.1' 
gem 'jquery-rails' 
gem 'jquery-ui-rails' 

# gem 'pg' 
gem 'sqlite3' 
gem 'mysql2', '~> 0.4.2' 

# Use Bootstrap 
gem 'bootstrap-sass', '~> 3.3.5' 
# Use Font-Awesome 
gem 'font-awesome-sass' 
# Sprockets 
gem 'sprockets', '~> 2.8' 
# Use SCSS for stylesheets 
gem 'sass-rails', '>= 3.2' 
# Use CoffeeScript for .coffee assets and views 
gem 'coffee-rails', '~> 4.1.0' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 

# See https://github.com/rails/execjs#readme for more supported runtimes 
gem 'therubyracer', platforms: :ruby 

# Use Autoprefixer 
gem 'autoprefixer-rails' 
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 
gem 'turbolinks' 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 2.0' 
# bundle exec rake doc:rails generates the API under doc/api. 
gem 'sdoc', '~> 0.4.0', group: :doc 

#gem 'pygments.rb', '~> 0.6.0' 
gem 'redcarpet', '~> 3.3.4' 

# Mail Forms 
gem 'mail_form', '~> 1.5', '>= 1.5.1' 
gem 'sendgrid' 

# Use ActiveModel has_secure_password 
# gem 'bcrypt', '~> 3.1.7' 

# Use PUMA 
gem 'puma' 

# Use Passenger as the app server 
gem 'passenger' 

# Use Devise for security 
gem 'devise', '~> 3.5', '>= 3.5.6' 
# Use figaro for environment variables (aka. passwords) 
gem 'figaro', '~> 1.1', '>= 1.1.1' 

group :assets do 
    gem 'compass-rails' 
    # Add any compass extensions here 
end 


group :development, :test do 
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console 
    gem 'byebug' 
end 

group :development do 
    # Access an IRB console on exception pages or by using <%= console %> in views 
    gem 'web-console', '~> 2.0' 

    gem 'capistrano-figaro-yml', '~> 1.0.2' 

    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 
    gem 'spring' 
end 

group :production, :staging do 

# Use Capistrano for deployment 
    gem 'capistrano', '~> 3.1' 
    gem 'capistrano-rails', '~> 1.1.1' 
    gem 'capistrano-passenger' 
    gem 'capistrano-bundler', '~> 1.1', '>= 1.1.4' 
    gem 'capistrano-rbenv', '~> 2.0.4' 
    # postgress 
    #gem 'pg' 
    gem 'rails_12factor' 
end 

环境/生产中n.rb:

Rails.application.configure do 

    # 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  = false 
    config.action_controller.perform_caching = true 

    # Disable serving static files from the `/public` folder by default since 
    # Apache or NGINX already handles this. 
    #config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 

    # 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 
    config.assets.initialize_on_precompile = false 

    # Asset digests allow you to set far-future HTTP expiration dates on all assets, 
    # yet still be able to expire them through the digest params. 
    config.assets.digest = false 

    # `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 

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

    config.action_mailer.perform_deliveries = true 
    # Bad email addresses and 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 = true 

    config.action_mailer.delivery_method = :smtp 

    ActionMailer::Base.smtp_settings = { 
    :address => "smtp.sendgrid.net", 
    :port => 587, 
    :user_name => ENV['SENDGRID_USER'], 
    :password => ENV['SENDGRID_PASS'], 
    :domain => "domain.com", 
    :authentication => :plain, 
    :enable_starttls_auto => true 
    } 

    # 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 

    # 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 

配置/ deploy.rb

# config valid only for current version of Capistrano 
lock '3.4' 

set :application, 'MyApplication' 

set :user, 'user' 

set :assets_roles, [:web, :app] 
set :keep_assets, 2 

# Default value for :scm is :git 
set :scm, :git 
set :repo_url, '[email protected]:CoreyVincent/HydraWeb.git' 

set :passenger_restart_with_touch, true 

# Default branch is :master 
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp 

# Default deploy_to directory is /var/www/my_app_name 
set :deploy_to, '/home/user/MyApplication' 

set :rails_env, "production" 

# set :deploy_via, :copy 

# Default value for :format is :pretty 
# set :format, :pretty 

# Default value for :log_level is :debug 
# set :log_level, :debug 

# Default value for :pty is false 
# set :pty, true 
# set :use_sudo, true 

# Default value for :linked_files is [] 
# set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml') 

# Default value for linked_dirs is [] 
# set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system') 

set :linked_files, %w{config/database.yml config/secrets.yml} 
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} 

#set :assets_prefix, "" 

# Default value for default_env is {} 
# set :default_env, { path: "/opt/ruby/bin:$PATH" } 

# Default value for keep_releases is 5 
set :keep_releases, 5 

namespace :deploy do 

    desc 'Restart application' 
    task :restart do 
    on roles(:app), in: :sequence, wait: 5 do 
     execute :touch, release_path.join('tmp/restart.txt') 
    end 
    end 

    after :publishing, 'deploy:restart' 
    after :finishing, 'deploy:cleanup' 
end 

更新:现在

资产和样式都显示出来,但我似乎无法进行任何更新。现在,当我推入并部署时,资产不会更新到新的更改...

回答

0

您可以将config.serve_static_files设置为true或使您的Web服务器提供这些文件。 我使用Nginx(以及乘客)与此配置:

server { 
... 
passenger_enabled on; 
... 
location ~* ^/assets/ { 
    expires 1y; 
    add_header Cache-Control public; 
    add_header Last-Modified ""; 
    add_header ETag ""; 
    break; 
} 
} 
+0

我有'passenger_enabled上;'设置已经开始。我添加了那些你在那里的其他行,但是这对我没有任何作用...... @standelaune – Corey

+0

@Corey现在似乎工作了;)。你做了什么 ? – rdupz

+0

将代码取出并再次部署后开始工作。不知道是什么修正了它... – Corey

相关问题