问题描述
我使用django-compression和django-storages在S3上提供我的压缩文件(使用这些说明:)。在运行compress管理命令之后,它最好运行起来,但是大约一个小时后,压缩的css和js文件即使我没有对文件进行任何更改也会返回403 Forbidden错误。我似乎无法孤立的问题,所以任何帮助将不胜感激。
I'm using django-compressor and django-storages to serve my compressed files on S3 (using these instructions: http://django_compressor.readthedocs.org/en/latest/remote-storages/#using-staticfiles). It works great initially after running the "compress" management command, but after about one hour the compressed css and js files return a 403 Forbidden error even though I haven't made any changes to the files. I can't seem to isolate the problem, so any help would be appreciated.
以下是我使用的设置:
COMPRESS_ENABLED = True
COMPRESS_URL = "http://mybucket.s3.amazonaws.com/"
COMPRESS_STORAGE = 'sm.storage.CachedS3BotoStorage'
COMPRESS_YUI_BINARY = os.path.join(PROJECT_ROOT, 'jars/yuicompressor-2.4.7.jar')
COMPRESS_CSS_FILTERS = ['compressor.filters.yui.YUICSSFilter',
'compressor.filters.css_default.CssAbsoluteFilter']
COMPRESS_JS_FILTERS = ['compressor.filters.yui.YUIJSFilter',]
COMPRESS_OFFLINE = True
STATICFILES_STORAGE = COMPRESS_STORAGE
STATIC_URL = COMPRESS_URL
STATIC_ROOT = '/path/to/static/'
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' # I'm using this for uploaded media
AWS_ACCESS_KEY_ID = 'myaccesskey'
AWS_SECRET_ACCESS_KEY = 'mysecretkey'
AWS_STORAGE_BUCKET_NAME = 'mybucket'
AWS_S3_FILE_OVERWRITE = True
AWS_HEADERS = {
'Cache-Control': 'public, max-age=31536000', #(1 year)
}
更新:当COMPRESS_OFFLINE为True时,似乎是一个问题。我将其设置为False,并且在初始请求期间创建的压缩文件正常工作,已经有一个多小时。但是,我宁愿使用管理命令预压缩这些文件。
UPDATE: This only seems to be a problem when COMPRESS_OFFLINE is True. I set it to False and the compressed files that were created during the initial request are working correctly and it has been over an hour. However, I would prefer to pre compress these files using the management command.
推荐答案
我可以通过添加这个来解决这个问题行到我的设置文件:
I was able to resolve this problem by adding this line to my settings file:
AWS_QUERYSTRING_AUTH = False
信用转到。
这篇关于为什么S3上的压缩文件返回403 Forbidden错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!