Problem with uwsgi_no_cache

Francis Daly francis at
Thu Aug 13 07:47:25 UTC 2015

On Thu, Aug 13, 2015 at 12:06:50AM -0400, daveyfx wrote:

Hi there,

> I'm attempting to exclude application/json data from storing in nginx's
> cache.  All other content types are OK to cache.  I thought that the below
> config would work for me, but nginx is still caching everything that is
> proxying.  What am I doing wrong?
> ## in http block ##
>     map $http_content_type $no_cache {

$http_ variables refer to the request from the client to
nginx. ($http_)

You want to care about the response from upstream to nginx.

Look at $upstream_http_ variables ($upstream_http_)

>        default 0;
>        "application/json" 1;
>     }
> ## in vhost block ##
>     location / {
>        uwsgi_cache www;
>        uwsgi_cache_valid 200 10m;
>        uwsgi_cache_methods GET HEAD;
>        uwsgi_cache_bypass $no_cache;

That says "do not read the response from the cache if this is true".

Since you can only sensibly decide that after the upstream response has
been fetched, you probably do not want that here.

>        uwsgi_no_cache $no_cache;

That says "do not write to the cache if this is true".

You do want that.

Francis Daly        francis at

More information about the nginx mailing list