proxy_ignore_headers doesn't seem to work

Francis Daly francis at
Wed Jan 4 22:26:05 UTC 2012

On Wed, Jan 04, 2012 at 03:12:10PM -0500, piotr wrote:

Hi there,

> I'm trying to hide those headers, you can see it in config posted
> before:
> proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;

No, that's proxy_ignore_headers, not proxy_hide_header.

> proxy_cache_valid 200 302 600h;
> proxy_cache_valid any 90m;
> But as you can see, you can find expire, cache-control headers in proxy
> repsonse, and also in headers of stored cache files on disk. With values
> from upstream server, not those set in config.

What comes from upstream is stored on disk. That's expected.

proxy_ignore_headers determines which of upstream headers or
proxy_cache_valid is used by nginx to decide for how long nginx will
cache the response.

Separate from that, you can use "proxy_hide_header" to tell nginx not to
send some headers that came from upstream, to the client.

Separate from that (mostly), you can use "expires" to tell nginx how to
set Expires: and Cache-Control: headers in the response to the client.

"(mostly)" is there because nginx will only send a single Expires header,
so if you use "expires" to set one, then the one from upstream will not
go to the client, even if it isn't in "proxy_hide_header".

> I'm not sure now those times from my previous response, but whatever i
> do (delete cached files from disk, restart nginx, wait 10 minutes to
> expire files cached on disk), nginx is always returning in response
> cache-control and expire in 600 sec - taking this value from upstream
> server, not from the config file.

That is as expected, since you have no other value in the config file
to send in the response, and you have nothing in the config file to tell
nginx not to send what came from upstream.

> Also, file is stored on disk for 600s,
> after this time i can see in logs that nginx is downloading again file
> from upstream server. Nginx should cache files for 600h in current
> config, but i've also tried before other values, like 6h or 6d etc.

That observation, I don't understand.

You can examine the first few bytes of the on-disk cache file to see
when nginx thinks that it will become stale:

od -t dL $cache_file | head -n 1

The second and fourth numbers there are valid-until- and fetched-at-
timestamps, respectively. So if they are only 600 apart, then something
unexpected (to me) is happening.

When I use configuration like

> proxy_cache_valid 200 302 600h;
> proxy_cache_valid any 90m;

in 1.1.11, I see them being the expected 2160000 (seconds, = 600 hours)
apart for a http 200 response.

Good luck,

Francis Daly        francis at

More information about the nginx mailing list