【问题标题】:Protocol-relative urls in Django Compressor's manifest.jsonDjango Compressor 的 manifest.json 中的协议相关 url
【发布时间】:2014-07-01 08:28:51
【问题描述】:

我正在使用 Django Compressor 进行离线压缩并将压缩的静态文件存储在 Amazon S3 上。我的问题是manifest.json 通过将http:// 指定为协议来引用缓存文件:

<link rel=\"stylesheet\" 
 href=\"http://stage-media.dropspot-app.com.s3.amazonaws.com/static/CACHE/css/abffb776bf3e.css\" 
 type=\"text/css\" media=\"all\" /><link rel=\"stylesheet\" 
 href=\"http://stage-media.dropspot-app.com.s3.amazonaws.com/static/CACHE/css/9533603cdbaa.css\"     
 type=\"text/css\" media=\"screen\" 
/>

这会导致通过 HTTPS 访问页面时不会加载缓存文件: The page at 'https://example.com' was loaded over HTTPS, but ran insecure content from 'http://example.com.s3.amazonaws.com/static/CACHE/css/abffb776bf3e.css': this content should also be loaded over HTTPS.

解决方案是让 manifest.json 引用缓存的文件,但在 url 中没有 http:,但还没有找到以这种方式生成它的方法。

有没有办法使用相对协议的 url 生成 manifest.json

【问题讨论】:

    标签: django amazon-s3 django-staticfiles django-compressor


    【解决方案1】:

    这是一个老问题,但我最近花了很多时间试图解决它。
    这种配置将使django-compress 在清单和压缩标签中生成协议相关的url:

    AWS_S3_SECURE_URLS = False
    AWS_QUERYSTRING_AUTH = False
    AWS_S3_URL_PROTOCOL = ''
    AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
    
    STATIC_URL = "//%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION)
    

    AWS_S3_CUSTOM_DOMAIN 对向后兼容很重要,如果省略,这将不起作用。

    【讨论】:

      猜你喜欢
      • 2013-02-09
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 2016-11-03
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      相关资源
      最近更新 更多