1

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

我按照这里的说明进行操作,default_storage.exists 非常慢并且经常超时,我的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

我是否需要将 COMPRESS_URL 指向 CloudFront?

4

2 回答 2

1

Try pointing your COMPRESS_URL to cloudfront, should do the trick

于 2015-04-27T14:36:52.220 回答
0

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

AWS_S3_CUSTOM_DOMAIN = 'yourdistribution.cloudfront.net'

GitHub 上相关的 django-compressor 问题

于 2017-01-12T09:31:27.100 回答