简体   繁体   English

Rails Passenger / Capistrano / ubuntu应用不提供资产

[英]Rails Passenger/Capistrano/ubuntu App not serving assets

After changing css files I did a rake assets:precompile and pushed it up to git. 更改css文件后,我进行了rake asset:precompile并将其推至git。 Then did a new deploy with capistrano to my server. 然后使用capistrano将新部署到我的服务器。 Now none of my assets or styles are showing up on my page http://162.243.102.157/ . 现在,我的页面http://162.243.102.157/上都没有显示我的资产或样式。
The assets are on the production deployment server, but I can't seem to figure out why either passenger or Rails isn't serving and showing the assets to my website...? 这些资产在生产部署服务器上,但是我似乎无法弄清楚为什么不提供旅客或Rails并将其显示在我的网站上...?

My ruby -v is: 我的红宝石-v是:
2.2.3p173 2.2.3p173

Rails -v: Rails -v:
4.2.5.2 4.2.5.2

capfile: 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: 的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  

environments/production.rb: 环境/ production.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  

config/deploy.rb 配置/ 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, 'git@github.com: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  

Update: 更新:

Assets and styles are now showing up, but I can't seem to update anything. 资产和样式现在正在显示,但我似乎无法更新任何内容。 Now when I git push and deploy, the assets don't update to the new changes... 现在,当我git push和部署时,资产不会更新为新的更改...

You can set the config.serve_static_files setting to true or make your web server serve these files. 您可以将config.serve_static_files设置设置为true或使您的Web服务器提供这些文件。 I use Nginx (along with passenger) with this config : 我在此配置中使用Nginx(以及乘客):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails Ubuntu / passenger / capistrano应用程序资产未部署 - Rails Ubuntu/passenger/capistrano app assets not deploying Nginx / Passenger / Capistrano上的Rails应用程序:资产不起作用 - Rails app on Nginx/Passenger/Capistrano: assets not working Rails 应用程序登录 ubuntu 服务器(nginx+passenger+capistrano)在哪里? - Where is the Rails app log on ubuntu server (nginx+passenger+capistrano)? Rails应用程序不提供资产 - rails app not serving assets 如何在Ubuntu上切换生产Rails应用程序(passenger / nginx / capistrano)以使用RVM? - How can I switch a production rails app (passenger/nginx/capistrano) to use RVM on Ubuntu? Passenger + Capistrano + Apache = Rails应用程序未运行 - Passenger + Capistrano + Apache = Rails app not running Rails应用程序与乘客和capistrano挑选错误的宝石 - Rails app with passenger and capistrano picking wrong gemset Capistrano + NGINX Passenger重启Rails应用程序 - Capistrano + NGINX Passenger Restart Rails App Passenger,Nginx和Capistrano - 乘客根本没有启动Rails应用程序 - Passenger, Nginx, and Capistrano - Passenger not launching Rails app at all Elastic Beanstalk乘客独立轨道不提供静态资产 - Elastic Beanstalk Passenger-Standalone Rails not serving static assets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM