実現したいこと
Rails6でBlocked hostエラーが発生し、ググって出てきた対処法を試したが修正できませんでした。
development.rbに
config.hosts << "instaautopost.com"
config.hosts.clear
の両方のパターンを入力し、unicornを再起動しました。
しかしBlocked hostエラーが消えませんでした。
前提
未経験からのエンジニア転職を目指しているの者です。
ポートフォリオとしてRailsでアプリケーションを作成しています。
インフラにはAWSを使用していて、NGINXとunicornを使用しています。
※不足情報がありましたら質問をお願いします
まだまだrailsの仕組みを理解していないので、初歩的な間違いをしている可能性があると思います。
発生している問題・エラーメッセージ
・こちらはデプロイしたサイトにアクセスしたときのエラー文です。
Blocked host: instaautopost.com
To allow requests to instaautopost.com make sure it is a valid hostname (containing only numbers, letters, dashes and dots), then add the following to your environment configuration:
config.hosts << "instaautopost.com"
・こちらはdevelopment.rbを修正した後に、Railsコンソールでホストの設定を確認したものです。
なぜか空欄になっています。修正が反映されていないということでしょうか?
[ec2-user@ip-10-2-1-10 original_product]$ bundle exec rails console
Loading development environment (Rails 7.0.6)
irb(main):001:0> Rails.application.config.hosts
=> []
development.rb
以下修正した後の2つのファイルです。
ruby
1require "active_support/core_ext/integer/time" 2 3Rails.application.configure do 4 # Settings specified here will take precedence over those in config/application.rb. 5 6 # In the development environment your application's code is reloaded any time 7 # it changes. This slows down response time but is perfect for development 8 # since you don't have to restart the web server when you make code changes. 9 config.cache_classes = false 10 11 # Do not eager load code on boot. 12 config.eager_load = false 13 14 # Show full error reports. 15 config.consider_all_requests_local = true 16 17 # Enable server timing 18 config.server_timing = true 19 20 21 # Enable/disable caching. By default caching is disabled. 22 # Run rails dev:cache to toggle caching. 23 if Rails.root.join("tmp/caching-dev.txt").exist? 24 config.action_controller.perform_caching = true 25 config.action_controller.enable_fragment_cache_logging = true 26 27 config.cache_store = :memory_store 28 config.public_file_server.headers = { 29 "Cache-Control" => "public, max-age=#{2.days.to_i}" 30 } 31 else 32 config.action_controller.perform_caching = false 33 34 config.cache_store = :null_store 35 end 36 37 # Store uploaded files on the local file system (see config/storage.yml for options). 38 config.active_storage.service = :local 39 40 # Don't care if the mailer can't send. 41 config.action_mailer.raise_delivery_errors = false 42 43 config.action_mailer.perform_caching = false 44 45 # Print deprecation notices to the Rails logger. 46 config.active_support.deprecation = :log 47 48 # Raise exceptions for disallowed deprecations. 49 config.active_support.disallowed_deprecation = :raise 50 51 # Tell Active Support which deprecation messages to disallow. 52 config.active_support.disallowed_deprecation_warnings = [] 53 54 # Raise an error on page load if there are pending migrations. 55 config.active_record.migration_error = :page_load 56 57 # Highlight code that triggered database queries in logs. 58 config.active_record.verbose_query_logs = true 59 60 # Suppress logger output for asset requests. 61 config.assets.quiet = true 62 63 # Raises error for missing translations. 64 # config.i18n.raise_on_missing_translations = true 65 66 # Annotate rendered view with file names. 67 # config.action_view.annotate_rendered_view_with_filenames = true 68 69 # Uncomment if you wish to allow Action Cable access from any origin. 70 # config.action_cable.disable_request_forgery_protection = true 71 72 config.hosts.clear 73 74end 75
production.rb
ruby
1 2require "active_support/core_ext/integer/time" 3 4Rails.application.configure do 5 # Settings specified here will take precedence over those in config/application.rb. 6 7 # Code is not reloaded between requests. 8 config.cache_classes = true 9 10 # Eager load code on boot. This eager loads most of Rails and 11 # your application in memory, allowing both threaded web servers 12 # and those relying on copy on write to perform better. 13 # Rake tasks automatically ignore this option for performance. 14 config.eager_load = true 15 16 # Full error reports are disabled and caching is turned on. 17 config.consider_all_requests_local = false 18 config.action_controller.perform_caching = true 19 20 # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 21 # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 22 # config.require_master_key = true 23 24 # Disable serving static files from the `/public` folder by default since 25 # Apache or NGINX already handles this. 26 config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? 27 28 # Compress CSS using a preprocessor. 29 # config.assets.css_compressor = :sass 30 31 # Do not fallback to assets pipeline if a precompiled asset is missed. 32 config.assets.compile = true 33 34 # Enable serving of images, stylesheets, and JavaScripts from an asset server. 35 # config.asset_host = "http://assets.example.com" 36 37 # Specifies the header that your server uses for sending files. 38 # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache 39 # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX 40 41 # Store uploaded files on the local file system (see config/storage.yml for options). 42 config.active_storage.service = :local 43 44 # Mount Action Cable outside main process or domain. 45 # config.action_cable.mount_path = nil 46 # config.action_cable.url = "wss://example.com/cable" 47 # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] 48 49 # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 50 # config.force_ssl = true 51 52 # Include generic and useful information about system operation, but avoid logging too much 53 # information to avoid inadvertent exposure of personally identifiable information (PII). 54 config.log_level = :info 55 56 # Prepend all log lines with the following tags. 57 config.log_tags = [ :request_id ] 58 59 # Use a different cache store in production. 60 # config.cache_store = :mem_cache_store 61 62 # Use a real queuing backend for Active Job (and separate queues per environment). 63 # config.active_job.queue_adapter = :resque 64 # config.active_job.queue_name_prefix = "instapost_production" 65 66 config.action_mailer.perform_caching = false 67 68 # Ignore bad email addresses and do not raise email delivery errors. 69 # Set this to true and configure the email server for immediate delivery to raise delivery errors. 70 # config.action_mailer.raise_delivery_errors = false 71 72 # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 73 # the I18n.default_locale when a translation cannot be found). 74 config.i18n.fallbacks = true 75 76 # Don't log any deprecations. 77 config.active_support.report_deprecations = false 78 79 # Use default logging formatter so that PID and timestamp are not suppressed. 80 config.log_formatter = ::Logger::Formatter.new 81 82 # Use a different logger for distributed setups. 83 # require "syslog/logger" 84 # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") 85 86 if ENV["RAILS_LOG_TO_STDOUT"].present? 87 logger = ActiveSupport::Logger.new(STDOUT) 88 logger.formatter = config.log_formatter 89 config.logger = ActiveSupport::TaggedLogging.new(logger) 90 end 91 92 # Do not dump schema after migrations. 93 config.active_record.dump_schema_after_migration = false 94 95 config.hosts.clear 96 97end 98 99
試したこと
以下の両方のパターンをファイルに入力して試しました。
config.hosts << "instaautopost.com"
config.hosts.clear
その後unicornを再起動し、ページをリロードしましたがエラー文の表示が変わりませんでした。
なぜファイルの修正が反映されないのか理解できずに苦しんでいます。(自分の考えでは反映されていないと解釈しています。)
ファイル修正後にちゃんと保存はしています。念のためNGINXの再起動もしています。
AWSのヘルスチェックもグリーンになっています。
独自ドメインではなくDNS名でもアクセスしてみましたが同じエラーが出ます。
https://instaautopost-1035613669.ap-northeast-1.elb.amazonaws.com/
ちなみにですがパブリックIPアドレスでアクセスした時は、エラーが出ずにアプリの画面が正常に表示されました。
独自ドメインの問題なのでしょうか??
http://18.180.75.39/
補足情報(FW/ツールのバージョンなど)
Windows10
chrome
Rails 7.0.6
調査の参考までにGithubのURLも貼っておきます。
https://github.com/tomo178/original_product/tree/master

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。