状況
Railsで作られたアプリをEC2にデプロイしました。
ブラウザ上で動作を確認したところ、背景画像の表示ができず困っています。
下記写真のようにローカルでは表示されるのですが
本番環境ですと真っ白な状態です。
Nginxやunicornのログ、またproductionログを確認してもエラーは発生していませんでした。
動作を確認したブラウザ(chrome,brave)の開発者ツールで確認してもエラーは発生していません。
写真上部はrailsのskipperというスライドショー機能を使っています。
下部はシンプルに写真を背景として設定しています。
また、写真はアセットパイプラインによってプリコンパイルされpublic/assetsに格納されています。
関連のありそうなファイルを下記に記します。
- /var/www/rails/アプリ名/app/assets/stylesheets/application.scss
SCSS
1#box{ 2 height: 600px; 3 margin-top: 200px; 4 } 5 .image1 { 6 background-image:image-url('fot0016-013.jpg'); 7 } 8 .image2 { 9 background-image:image-url('hnb0041-049.jpg'); 10 } 11 .image3 { 12 background-image:image-url('poo0042-022.jpg'); 13 } 14 .image4 { 15 background-image:image-url('yak0059-021.jpg'); 16 } 17 .image5 { 18 background-image:image-url('yuu0019-002.jpg'); 19 } 20 21 img.sized { 22 width: 50%; 23 height: 50%; 24 } 25 26 .test-bk { 27 background-image:image-url('yuu0019-002.jpg'); 28 height: 800px; 29 background-size: cover; 30 }
- config/environments/production.rb
Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. 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 # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. # config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? config.public_file_server.enabled = true # 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 = true # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # 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 # Store uploaded files on the local file system (see config/storage.yml for options) config.active_storage.service = :local # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = false # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "insta_#{Rails.env}" config.action_mailer.perform_caching = false config.require_master_key = true # Ignore bad email addresses and do not 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 = false # 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 # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end
解決方法をご教授頂きましたら幸いです。
試したこと
- public/imageに画像を配置してみた
- production.rbのconfig.public_file_server.enabledをtrueに変更した
- application.cssをapplication.scssに変更した
- 様々なサイトを参照しトライ&エラーを繰り返した
(scssの記載方法や画像ファイルの格納場所)
環境
ruby 2.6.6
Rails 5.2.4.4
Unicorn 6.0.0
Nginx 1.16.1
Mysql 8.0.23
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。