Skip to content
This repository

403 Forbidden for compressed files on S3 #229

Closed
godshall opened this Issue March 10, 2012 · 4 comments

3 participants

Michael Godshall Damon Jablons Ahmet Emre Aladağ
Michael Godshall

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 direction you can provide 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)
}

Michael Godshall

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.

Damon Jablons

I'm also having this issue. It seems that it's being caused by the Signature GET variable being appended to the cached file url.

Upon further investigation, this is being caused by django-storages. It will automatically add the auth headers to the urls when they're returned. See here: http://code.larlet.fr/django-storages/issue/51/please-improve-s3-storage-documentation

In order to disable that behavior, add this to your settings:

AWS_QUERYSTRING_AUTH = False
Michael Godshall

blackrobot, thanks for your suggestion. Setting AWS_QUERYSTRING_AUTH = False seems to have resolved the problem.

Michael Godshall godshall closed this March 13, 2012
Ahmet Emre Aladağ

The problem persists in my case. When COMPRESS_ENABLED, js/css files are told to be expired. AWS_QUERYSTRING_AUTH=False didn't help either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.