[英]403 Forbidden on Django Storages css/js files with Amazon S3 on an EC2 Instance
I have been googling for two days and none of the answers are resolving the issue. 我一直在谷歌搜索两天,没有一个答案正在解决这个问题。
The setup 设置
AWS_S3_ACCESS_KEY_ID = 'xxxxxxx'
AWS_S3_SECRET_ACCESS_KEY = 'xxxxxxxxx'
AWS_STORAGE_BUCKET_NAME = 'my-bucket.mycompany.com'
COMPRESS_URL = 'http://{}.s3.amazon.com/'.format(AWS_STORAGE_BUCKET_NAME)
STATIC_URL = COMPRESS_URL
AWS_S3_FILE_OVERWRITE = True
AWS_S3_SECURE_URLS = True
AWS_QUERYSTRING_AUTH = False
AWS_S3_CUSTOM_DOMAIN = '{}.s3-external-3.amazonaws.com'.format(AWS_STORAGE_BUCKET_NAME)
The googling 谷歌搜索
Incorrect date/time on server : This an EC-2 instance, but even though I installed yum install ntp ntpdate ntp-doc
-- NO LUCK 服务器上的日期/时间不正确 :这是一个EC-2实例,但即使我安装了yum install ntp ntpdate ntp-doc
- NO LUCK
AWS_QUERY_STRING_AUTH : Multiple sources online say to do this, but didn't resolve my issue AWS_QUERY_STRING_AUTH :在线多个来源说要执行此操作,但无法解决我的问题
AWS_QUERY_STRING_AUTH : Yet again AWS_QUERY_STRING_AUTH :再一次
AWS_S3_CUSTOM_DOMAIN No luck here either AWS_S3_CUSTOM_DOMAIN也没有运气
The experiment 本实验
# ON THE EC2 BOX
./manage.py shell
from boto.s3.connection import S3Connection
from django.conf import settings
conn = S3Connection(settings.AWS_S3_ACCESS_KEY_ID, settings.AWS_S3_SECRET_ACCESS_KEY)
b = conn.get_bucket('my-bucket.mycompany.com')
key = b.get_key('500.html')
print key.get_contents_as_string() # WORKS FINE
However when I run ./manage.py compress
I get 但是,当我运行./manage.py compress
我得到了
CommandError: An error occured during renderinghome_4770.html:
'https://mybucket.mycompany.com.s3-external-3.amazonaws.com/css/smoothness/jquery-ui-1.10.1.custom.css'
isn't accessible via COMPRESS_URL ('http://mybucket.mycompany.com.s3.amazon.com/') and can't be compressed
Before you ask, yes the file is available on that bucket. 在您提出之前,是的,该文件在该存储桶上可用。 I also tried the traditional way of django-storages with offline compression, using <project-root>/static
as STATIC_ROOT
, then uploading the contents of ./manage.py collectstatic
AND ./manage.py compress
:, ie the resulting css/js and manifest_1.json
files to the bucket, but in the browser, I still get 403 Forbidden
on css/js files 我还尝试了传统的django-storage与离线压缩方式,使用<project-root>/static
作为STATIC_ROOT
,然后上传./manage.py collectstatic
AND ./manage.py compress
:的内容,即生成的css / js和manifest_1.json
文件到桶中,但在浏览器中,我仍然在css / js文件上获得403 Forbidden
Any ideas on what may be going on?? 关于可能发生什么的任何想法?
Have you set up a CORS policy on your bucket? 您是否在桶上设置了CORS策略? You might also need to add a permission to allow "Everyone" to "List" objects in the bucket (although try the CORS policy first) 您可能还需要添加权限以允许“Everyone”在桶中“列出”对象(尽管首先尝试CORS策略)
Edit: Here are the docs: http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html 编辑:以下是文档: http : //docs.aws.amazon.com/AmazonS3/latest/dev/cors.html
Did you check your css file metadata ( ==> File ==> Properties)? 你检查了你的css文件元数据(==>文件==>属性)吗?
make sure they are set as css files and not as: "binary/octet-stream" 确保它们被设置为css文件而不是:“binary / octet-stream”
Like AWS does sometime. 像AWS一样。
I had a similar problem that seems to be caused by mixing storage.CachedStaticFilesStorage
with storage.backends.s3boto.S3BotoStorage
. 我有一个类似的问题似乎是由storage.CachedStaticFilesStorage
与storage.backends.s3boto.S3BotoStorage
混合引起的。
I didn't have time to diagnose the problem (which probably involved my CACHES
setup), but not using storage.CachedStaticFilesStorage
with S3 fixed my issue. 我没有时间诊断问题(这可能涉及我的CACHES
设置),但没有使用storage.CachedStaticFilesStorage
与S3解决了我的问题。
I am using the django-require-s3 package and had the following settings: 我使用的是django-require-s3软件包并进行了以下设置:
DEFAULT_FILE_STORAGE = STATICFILES_STORAGE = 'require_s3.storage.OptimizedCachedStaticFilesStorage'
First solution: https://stackoverflow.com/a/19110977/1074659 第一个解决方案: https : //stackoverflow.com/a/19110977/1074659
# Add
AWS_QUERYSTRING_AUTH = False
Second solution: 二解决方案:
# Alter
DEFAULT_FILE_STORAGE = STATICFILES_STORAGE = 'require_s3.storage.OptimizedStaticFilesStorage'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.