解决静态资产的nginxcaching问题

我有一个Django网站,用户发布整个社区的图像(有点像9gag)。

我使用Azure存储来保存和提供图像。 networking服务器是一个nginx反向代理+ gunicorn鸡尾酒。 Gzip启动并运行在我的网站上此外,为了caching静态资产,我在我的nginx conf文件中有以下内容:

location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { root /home/mhb11/project/myproject; expires 24h; add_header Vary Accept-Encoding; access_log off; } 

我的问题是,当我使用Google Page Speed插件testing我的网站时,我被告知没有任何来自Azure存储的图像被caching: 在这里输入图像说明

我该如何为这些caching启用? 请指教。 我对此很新,所以现阶段的任何帮助都会有很大的帮助。 在此先感谢,并有一个愉快的周末。


下面是我自定义存储类的def _save方法,上传一个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 ) 

如何在其中设置Cache-Control?

您需要在Azure存储/ blob中设置“caching控制”元标记信息。

我使用AWS,在那里我可以去特定的资产(你的图片),并指定信息。

也; 你应该能够指定这个设置,如果你正在使用某种types的API从应用程序上传图像。