I have a Django website where users post images for the whole community to see (kind of like 9gag).
I use Azure storage to save and serve the images. The webserver is an nginx reverse proxy + gunicorn cocktail. Gzip is up and running on my website Moreover, in order to cache the static assets, I have the following in my nginx conf file:
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { root /home/mhb11/project/myproject; expires 24h; add_header Vary Accept-Encoding; access_log off; }
My problem is that when I test my website with Google Page Speed plugin, I get told that none of the images being served from Azure storage are being cached:
What do I do to enable caching for these? Please advise. I'm quite new to this, so any assist at this stage will be a big help. Thanks in advance, and have a nice weekend.
Here's the def _save
method of my custom Storage class that uploads a blob:
def _save(self,name,content):
blob_service = BlobService(account_name=accountName, account_key=accountKey)
import mimetypes
small_content = content
content.open()
content_type = None
if hasattr(content.file, 'content_type'):
content_type = content.file.content_type
else:
content_type = mimetypes.guess_type(name)[0]
content_str = content.read()
blob_service.put_blob(
'pictures',
name,
content_str,
x_ms_blob_type='BlockBlob',
x_ms_blob_content_type=content_type
)
How do I set Cache-Control within that?