caching: Expires takes precedence over max-age

Maxim Dounin mdounin at mdounin.ru
Fri Aug 2 12:00:45 UTC 2013


Hello!

On Thu, Aug 01, 2013 at 03:59:45AM -0400, hippo wrote:

> Hello, I have a trouble with nginx caching pages it shouldn't cache. I have
> uwsgi_cache enabled:
> 
> uwsgi_cache_path /tmp/cache levels=1:2 keys_zone=django:1m;
> location /test {
>     uwsgi_pass unix:/tmp/uwsgi.sock;
>     uwsgi_cache django;
> }
> 
> nginx caches responses that have Expires header set in the future, even if
> Cache-Control says otherwise:
> 
> Expires: Fri, 02 Aug 2013 19:47:42 GMT
> Cache-Control: no-cache, must-revalidate, max-age=0
> 
> And rfc2616 says:
> 
> Note: if a response includes a Cache-Control field with the max-
> age directive (see section 14.9.3), that directive overrides the
> Expires field.
> 
> Happens on nginx 1.2.1 and 1.4.1. If I add "uwsgi_ignore_headers Expires;"
> to the nginx conf, the pages don't get cached. Is there something wrong with
> my nginx or uwsgi response headers?

As of now nginx treats both Expires and "Cache-Control: max-age" 
with equal precedence, and uses whichever comes first.  
X-Accel-Expires takes precedence over both of them.

-- 
Maxim Dounin
http://nginx.org/en/donation.html



More information about the nginx mailing list