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.
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