使用django-compressor和AWS CloudFront时出错

时间:2014-08-04 13:52:43

标签: django boto amazon-cloudfront django-storage django-compressor

我已成功使用django-compressordjango-storages来管理Django 1.6中静态文件的压缩和部署。我现在正在尝试使用AWS CloudFront来提供我的静态文件。

我按照default_storage.exists extremely slow and frequently times out中的说明操作,我的settings.py文件如下所示:

COMPRESS_ENABLED = True

STATIC_ROOT = os.path.join(
    os.path.dirname(
        os.path.dirname(
            os.path.abspath(__file__))), 'static')
COMPRESS_ROOT = STATIC_ROOT

COMPRESS_OFFLINE = True

COMPRESS_URL = "https://compressor-test.s3.amazonaws.com/"
STATIC_URL = COMPRESS_URL

COMPRESS_STORAGE = 'mysite.storage.CachedS3BotoStorage'
STATICFILES_STORAGE = COMPRESS_STORAGE

AWS_STORAGE_BUCKET_NAME = 'compressor-test'
AWS_S3_CUSTOM_DOMAIN = '1234567.cloudfront.net'

但是我收到以下错误:

Exception Type:     UncompressableFileError
Exception Value:    

'https://1234567.cloudfront.net/bootstrap/css/bootstrap.min.css' isn't accessible via COMPRESS_URL ('https://compressor-test.s3.amazonaws.com/') and can't be compressed

我是否需要在CloudFront上指向COMPRESS_URL?

2 个答案:

答案 0 :(得分:0)

尝试将COMPRESS_URL指向云端,应该诀窍

答案 1 :(得分:0)

要将静态文件写入S3,但从Cloudfront读取,请使用:

AWS_S3_CUSTOM_DOMAIN = 'yourdistribution.cloudfront.net'

Related django-compressor issue on GitHub