2016-09-28 99 views
0

您好我正在使用Capistrano将我的第一个Rails应用程序部署到Ubuntu 16服务器,除非图像没有在生产环境中显示,否则一切都很流畅。使用Passenger/Capistrano部署到Nginx服务器后未显示图像

在生产服务器上的图像都位于此路径:/myapp/current/public/assets

但是,如果我在浏览器中看看这个我破碎的图片链接给我这个(见图),这是一个破碎的链接标题图片。

broken images

奇怪的是,有一个.svg文件中的/myapp/current/public/assets这是完全显示在浏览器中时,在下面的图片所示 svg file

的路径,这是我的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,与任何运气

我几乎想尽一切答案在这里类似的问题上堆栈溢出,但似乎没有任何工作。

我失去了一些东西在这里?

我确定这个问题与资产管道有关,但我不确定如何解决它。

任何人都可以请看看这个,并告诉我。

在此先感谢

回答

4

好吧,如果有人遇到了类似的问题,你可能要检查出config.assets.compile在我来说,我只有到config /环境/ production.rb config.assets.compilefalse改变,我把它改成true,现在一切工作。 ...它只花了我两天的时间弄清楚:D

1

注意public/assets就是资产管道把它的东西。如果这是静态资产,我会将它们放在app/assets/images以使用资产管道,或者选择另一个目录名称。

+0

我该如何在服务器上做到这一点?我的意思是,在部署到服务器的过程中,我该怎么做? – DaudiHell

+0

您可以更改源树或部署流程来解决它。你的capistrano进程已经连接公共/系统,所以我只是用它。 – Eric

+0

好的,谢谢,我明白了,但我没有明白:)是的,我该如何更改源代码树? – DaudiHell