gpt4 book ai didi

ruby-on-rails - 使用 Passenger/Capistrano 部署到 Nginx 服务器后图像不显示

转载 作者:行者123 更新时间:2023-12-05 08:42:36 27 4
gpt4 key购买 nike

您好,我正在使用 Capistrano 将我的第一个 Rails 应用程序部署到 Ubuntu 16 服务器,除了图像未在生产环境中显示外,一切都很顺利。

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

但是如果我在浏览器中查看这个,我的损坏的图片链接会给我这个(见图片),这是标题图片的损坏链接。

broken images

奇怪的是在/myapp/current/public/assets中有一个.svg文件在浏览器中完美显示,在图片中下面是显示的路径 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, 'git@github.com: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,没有任何运气

我已经尝试了几乎所有关于堆栈溢出的类似问题的答案,但似乎没有任何效果。

我是不是漏掉了什么?

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

任何人都可以看看这个并给我建议。

提前致谢

最佳答案

好的,如果有人遇到类似的问题,您可能需要查看 config.assets.compile 在我的例子中,我只需要更改 config/environments/production.rb config .assets.compile 来自 false,我将其更改为 true 现在一切正常....我只花了两天时间就弄明白了 :D

关于ruby-on-rails - 使用 Passenger/Capistrano 部署到 Nginx 服务器后图像不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39736174/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com