我已經成功地建立了我的應用程序使用S3存儲所有的靜態和媒體文件。不過,我想上傳到S3(當前操作),但是從我設置的雲端實例提供服務。我曾嘗試將設置調整到雲端網址,但它不起作用。我如何上傳到S3並從Cloudfront提供服務?使用的Cloudfront和Django S3Boto
設置
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
DEFAULT_FILE_STORAGE = 'app.custom_storages.MediaStorage'
STATICFILES_STORAGE = 'app.custom_storages.StaticStorage'
STATICFILES_LOCATION = 'static'
MEDIAFILES_LOCATION = 'media'
STATIC_URL = "https://s3-eu-west-1.amazonaws.com/app/%s/" % (STATICFILES_LOCATION)
MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)
custom_storages.py
from django.conf import settings
from storages.backends.s3boto import S3BotoStorage
class StaticStorage(S3BotoStorage):
location = settings.STATICFILES_LOCATION
class MediaStorage(S3BotoStorage):
location = settings.MEDIAFILES_LOCATION
你有更多的信息,爲什麼它不工作?任何錯誤消息? –
這一點已經在這裏找到答案:http://stackoverflow.com/questions/8688815/django-compressor-how-to-write-to-s3-read-from-cloudfront/8888930#8888930 –
如果它可以幫助任何人,我還必須將'collectstatic'的設置'AWS_DEFAULT_ACL ='''添加到工作中,而不是返回403. – Danra