【问题标题】:Rails s3 bucket SSLRails s3 存储桶 SSL
【发布时间】:2014-02-03 00:33:43
【问题描述】:

我的 rails 4 应用程序使用 Amazon s3 存储桶来存储图像。我的 production.rb 文件看起来像这样,配置是非常默认的

config.paperclip_defaults = {
  :storage => :s3,
  :s3_credentials => {
    :bucket => ENV['S3_BUCKET_NAME'],
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
  }
}

当页面加载图像时,它会像这样加载它:

http://s3.amazonaws.com/themoderntrunk/designs/photos/000/000/052/large_thumbnail/product12.jpeg?1389721666

我希望它加载前缀 https:

https://s3.amazonaws.com/themoderntrunk/designs/photos/000/000/052/large_thumbnail/product12.jpeg?1389721666    

没有 SSL,我的应用会在控制台中收到警告

he page at 'https://www.themoderntrunk.com/assortments/4/designs/52-product-12' was loaded over HTTPS, but displayed insecure content from 'http://s3.amazonaws.com/themoderntrunk/designs/photos/000/000/049/grid/product9.jpg?1389721643': this content should also be loaded over HTTPS.

当然,在我的 production.rb 文件中我有 config.forse_ssl = true。我的应用程序也有 SSL 证书。

【问题讨论】:

    标签: ruby-on-rails ssl amazon-web-services amazon-s3 ruby-on-rails-4


    【解决方案1】:

    你需要在模型中添加它

    class Designs < ActiveRecord::Base
      has_attached_file :photo, :s3_protocol => :https
    

    参考:Is it possible to configure Paperclip to produce HTTPS urls?

    【讨论】:

    • 你太棒了!谢谢!
    猜你喜欢
    • 2012-06-27
    • 2016-03-31
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 2016-08-25
    • 2010-10-23
    • 2015-04-25
    • 2014-12-06
    相关资源
    最近更新 更多