Why are my compressed files on S3 returning a 403 Forbidden error?

混江龙づ霸主 提交于 2019-12-08 02:53:34

问题


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.

Here are the settings I am using:

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)  
}  

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.


回答1:


I was able to resolve this problem by adding this line to my settings file:

AWS_QUERYSTRING_AUTH = False

Credit goes to blackrobot on github.



来源:https://stackoverflow.com/questions/9651052/why-are-my-compressed-files-on-s3-returning-a-403-forbidden-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!