expires headers and cache control

Francis Daly francis at daoine.org
Mon Oct 25 22:37:46 MSD 2010

On Mon, Oct 25, 2010 at 12:38:37PM -0400, Ilan Berkner wrote:

Hi there,

> I'm trying to understand expires headers and cache control better, maybe
> someone can help?
> our configuration file has:
>       location ~* \.(jpg|jpeg|gif|png|ico|css|js)$
>         {
>                 error_page 404 = /404.php;
>                 expires 31d;
>         }
> Which I understand to mean that for these file types, the expiration header
> should be set to 31 days from today. 


Strictly, it is for requests that are processed by this location
block. It's limited to "these file types", but it may not be *all* of
these file types, depending on the rest of your configuration. The debug
log should show you which one location block is used for each request.

> However, when I load the site, it
> looks like its being set 1 day ahead.

Look at the response headers of one request. "wget -S" or "curl -i"
can be useful for this. You'll see the Expires and any Cache-Control
headers that are returned. No need to guess anything.

If it doesn't show Expires: of 31 days in the future and the debug log
does show that this location block is being used, then something odd
is happening.

> I've also seen a lot of examples which use "add_header Cache-Control
> private;" but I don't understand what this actually means?

Searching google for "expires headers and cache control", the top link
for me right now is


which includes a section on "Add an Expires or a Cache-Control Header"
which gives a very coarse overview. The next two links are

 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html and

The first includes "14.9 Cache-Control", which pretty much says how
things should be for that header, including what "private" means. The
second is titled "Caching in HTTP", and is probably in more detail than
you want to know.

The fourth link is


which describes the RFCs, and also mentions some of the real-world
aspects that may not match the ideal.

All the best,

Francis Daly        francis at daoine.org

More information about the nginx mailing list