您好我正在使用Capistrano
將我的第一個Rails應用程序部署到Ubuntu 16服務器,除非圖像沒有在生產環境中顯示,否則一切都很流暢。使用Passenger/Capistrano部署到Nginx服務器後未顯示圖像
在生產服務器上的圖像都位於此路徑:/myapp/current/public/assets
但是,如果我在瀏覽器中看看這個我破碎的圖片鏈接給我這個(見圖),這是一個破碎的鏈接標題圖片。
奇怪的是,有一個.svg
文件中的/myapp/current/public/assets
這是完全顯示在瀏覽器中時,在下面的圖片所示
的路徑,這是我的Capfile
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, '2.3.1'
require 'capistrano/rbenv'
require 'capistrano/bundler'
require 'capistrano/rails'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
這是config/deploy.rb
# config valid only for current version of Capistrano
lock '3.6.1'
set :application, 'myapp'
set :repo_url, '[email protected]:DadiHall/myapp.git'
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/home/deploy/myapp'
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}
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'
末
這裏是environments/production.rb
Rails.application.configure do
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.js_compressor = :uglifier
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
config.assets.digest = true
config.assets.initialize_on_precompile = false
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
Braintree::Configuration.environment = :sandbox
Braintree::Configuration.merchant_id = ENV['merchant_id']
Braintree::Configuration.public_key = ENV['public_key']
Braintree::Configuration.private_key = ENV['private_key']
end
在/etc/nginx/sites-enabled/default
我有以下行
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name mydomain.com;
passenger_enabled on;
rails_env production;
root /home/deploy/myapp/current/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
這是Nginx的錯誤日誌
[ 2016-09-28 06:25:02.4500 1594/7f900ee89700 age/Sha/ApiServerUtils.h:794 ]: Log file reopened.
[ 2016-09-28 09:45:43.7508 1597/7f2326502700 age/Cor/CoreMain.cpp:819 ]: Checking whether to disconnect long-running connections for process 1978, application /home/deploy/hlinreykdal/current/public (production)
App 21337 stdout:
App 21405 stdout:
[ 2016-09-28 10:30:31.0631 1597/7f2326502700 age/Cor/CoreMain.cpp:819 ]: Checking whether to disconnect long-running connections for process 21405, application /home/deploy/hlinreykdal/current/public (production)
App 23240 stdout:
App 23308 stdout:
[ 2016-09-28 10:41:40.1769 1597/7f2326502700 age/Cor/CoreMain.cpp:819 ]: Checking whether to disconnect long-running connections for process 23308, application /home/deploy/hlinreykdal/current/public (production)
App 24329 stdout:
App 24397 stdout:
我試過bundle exec rake assets precompile
沒有任何運氣。
我已經部署了一次又一次重新開始nginx
,與任何運氣
我幾乎想盡一切答案在這裏類似的問題上堆棧溢出,但似乎沒有任何工作。
我失去了一些東西在這裏?
我確定這個問題與資產管道有關,但我不確定如何解決它。
任何人都可以請看看這個,並告訴我。
在此先感謝
我該如何在服務器上做到這一點?我的意思是,在部署到服務器的過程中,我該怎麼做? – DaudiHell
您可以更改源樹或部署流程來解決它。你的capistrano進程已經連接公共/系統,所以我只是用它。 – Eric
好的,謝謝,我明白了,但我沒有明白:)是的,我該如何更改源代碼樹? – DaudiHell