Carrierwave getaddrinfo:名称或服务未知

Carrierwave getaddrinfo: Name or service not known

我目前正在努力让 S3 上传通过 Carrierwave、Carrierwave-aws 和 Figaro 工作。

但我不断得到

OffersController 中的 SocketError#create

getaddrinfo: 名称或服务未知

我已尝试将资产主机更改为“127.0.0.1”,但似乎仍然会产生此错误。

carrierwave.rb

CarrierWave.configure do |config|
  config.storage    = :aws
  config.aws_bucket = ENV.fetch('S3_BUCKET_NAME')
  config.aws_acl    = 'public-read'

  # Optionally define an asset host for configurations that are fronted by a
  # content host, such as CloudFront.
  config.asset_host = 'localhost'

  # The maximum period for authenticated_urls is only 7 days.
  config.aws_authenticated_url_expiration = 60 * 60 * 24 * 7

  # Set custom options such as cache control to leverage browser caching
  config.aws_attributes = {
    expires: 1.week.from_now.httpdate,
    cache_control: 'max-age=604800'
  }

  config.aws_credentials = {
    access_key_id:     ENV.fetch('AWS_ACCESS_KEY_ID'),
    secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
    region:            ENV.fetch('AWS_REGION') # Required
  }

end

gemfile

# Figaro
gem "figaro"

# Carrierwave Integration
gem 'carrierwave'

# Carrierwave AWS
gem 'carrierwave-aws'

如果能对此提供任何帮助,那就太好了。

尝试从您的 CarrierWave.configure 中删除 config.asset_host = 'localhost'。可选,主要用于设置cloudfront等第三方资源路径。

所以删除 config.asset_host = 'localhost' 就大功告成了。