我在Amazon S3上設置了我的Django項目,DNS和存儲桶,但是python manage.py collectstatic
因此也手動上傳的文件不起作用。Django不會從自定義域名的Amazon S3提供靜態文件
AWS S3設置:
桶名稱:files.domain.com
桶政策:
{
"Id": "Policy1483363850641",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1483363848944",
"Action": "s3:*",
"Effect": "Allow",
"Resource": "arn:aws:s3:::files.domain.com/*",
"Principal": "*"
}
]
}
DNS設置:
files.domain.com - > CNAME - > files.domain.com.s3.amazonaws.com
Django的設置:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = 'XXXXXXXXXXXXXXXXXXXX'
AWS_SECRET_ACCESS_KEY = 'XxXxXXxXXXXXxxxXxxXXXxXxxXXXXXXXXxxxXxxx'
AWS_STORAGE_BUCKET_NAME = 'files.domain.com'
AWS_AUTO_CREATE_BUCKET = False
AWS_QUERYSTRING_AUTH = False
AWS_S3_SECURE_URLS = False
AWS_EXPIRY = 60 * 60 * 24 * 7
AWS_HEADERS = {
'Cache-Control': six.b('max-age=%d, s-maxage=%d, must-revalidate' % (
AWS_EXPIRY, AWS_EXPIRY))
}
MEDIA_URL = 'http://%s/' % AWS_STORAGE_BUCKET_NAME
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE
STATIC_URL = MEDIA_URL
是否有錯誤訊息? –
對不起。是。 ssl.CertificateError:hostname'files.domain.com.s3.amazonaws.com'與'* .s3.amazonaws.com','s3.amazonaws.com'中的任何一個都不匹配。' –
該問題與使用點有關在S3存儲桶名稱和BOTO上。有一個解決方案,但我沒有我的電腦給你一個答案,但希望這讓你搜索答案 – dkarchmer