# Proxy\_ignore\_headers doesn't seem to work

**URL:** <https://www.ruby-forum.com/t/proxy-ignore-headers-doesnt-seem-to-work/214879>\
**Category:** NGINX\
**Created:** [December 14, 2011, 5:34pm UTC](https://www.ruby-forum.com/t/proxy-ignore-headers-doesnt-seem-to-work/214879 "2011-12-14T17:34:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [December 14, 2011, 5:34pm UTC](https://www.ruby-forum.com/t/proxy-ignore-headers-doesnt-seem-to-work/214879/1 "2011-12-14T17:34:40Z")

</div>

Hello,

I’ve problem similar as in this thread:  
[http://mailman.nginx.org/pipermail/nginx/2010-May/020349.html](http://mailman.nginx.org/pipermail/nginx/2010-May/020349.html)

nginx is ignoring my proxy\_cache\_valid value, using instead expire time  
specified by upstream server.

proxy\_ignore\_headers X-Accel-Expires Expires Cache-Control  
Set-Cookie;  
proxy\_cache\_valid 200 302 30h;  
proxy\_cache\_valid any 1h;

headers from file stored on cache:

* * *

KEY: [httpXYZ.com/tiles/1.0.0/osm/15/5240/12662.jpg](http://httpXYZ.com/tiles/1.0.0/osm/15/5240/12662.jpg)  
HTTP/1.0 200 OK  
Expires: Wed, 14 Dec 2011 16:33:27 GMT  
Last-Modified: Tue, 13 Dec 2011 06:16:41 GMT  
Cache-Control: max-age=600  
Content-Type: image/jpeg  
Content-Length: 27946  
Server: Mapnik2/0.8.0  
Date: Wed, 14 Dec 2011 16:23:27 GMT  
Connection: close

* * *

from logs:

* * *

14/Dec/2011:10:02:11 -0600 HIT Cache-Control:max-age=600 Expires:Wed, 14  
Dec 2011 16:09:55 GMT upstream\_server:- upstream\_status:- (…)  
14/Dec/2011:10:22:55 -0600 MISS Cache-Control:max-age=600 Expires:Wed,  
14 Dec 2011 16:32:55 GMT upstream\_server(…)

* * *

I’ve tried to add also Date and Last-Modified to proxy\_ignore\_headers,  
adding same headers to proxy\_hide\_header, but without any luck.

nginx/0.8.54 from source on RHEL5.7, and nginx/1.0.10 from official deb  
package on Ubuntu10.04.

Does anybody have any idea what could be wrong?

Thanks!

Piotr

Posted at Nginx Forum:

> **[proxy\_ignore\_headers doesn't seem to work](https://forum.nginx.org/read.php?2,220058,220058#msg-220058)**
>
> Hello, I've problem similar as in this thread: http://mailman.nginx.org/pipermail/nginx/2010-May/020349.html nginx is ignoring my proxy\_cache\_valid value, using instead expire time specified by upstream server. proxy\_ignore\_headers X-Accel-Expires Ex

---

<div class="post-metadata">

**Author:** ![piotr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@piotr](https://www.ruby-forum.com/u/piotr)\
**Post date:** [December 14, 2011, 6:10pm UTC](https://www.ruby-forum.com/t/proxy-ignore-headers-doesnt-seem-to-work/214879/2 "2011-12-14T18:10:31Z")

</div>

Hello!

On Wed, Dec 14, 2011 at 11:34:15AM -0500, piotr wrote:

> proxy\_cache\_valid 200 302 30h;  
> Content-Length: 27946  
> 14 Dec 2011 16:32:55 GMT upstream\_server(…)
> 
> * * *
> 
> I’ve tried to add also Date and Last-Modified to proxy\_ignore\_headers,  
> adding same headers to proxy\_hide\_header, but without any luck.
> 
> nginx/0.8.54 from source on RHEL5.7, and nginx/1.0.10 from official deb  
> package on Ubuntu10.04.
> 
> Does anybody have any idea what could be wrong?

Try “nginx -t”. If it doesn’t help, please post the full config  
you’re testing with.

Maxim D.

---

<div class="post-metadata">

**Author:** ![piotr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@piotr](https://www.ruby-forum.com/u/piotr)\
**Post date:** [December 18, 2011, 12:18pm UTC](https://www.ruby-forum.com/t/proxy-ignore-headers-doesnt-seem-to-work/214879/3 "2011-12-18T12:18:34Z")

</div>

Hello!

On Sat, Dec 17, 2011 at 10:19:29AM -0500, piotr wrote:

> I’ve checked both servers for config errors before, but without any  
> clues.

[…]

> Accept-Encoding: gzip, deflate  
> Connection: keep-alive  
> Note:  
> Expires == Date + Cache-Control max-age.

> Accept-Charset: ISO-8859-2,utf-8;q=0.7,\*;q=0.7  
> Date: Fri, 16 Dec 2011 14:08:43 GMT  
> Content-Type: image/jpeg  
> Connection: keep-alive  
> Expires: Wed, 14 Dec 2011 14:59:21 GMT  
> Last-Modified: Tue, 13 Dec 2011 06:16:41 GMT  
> Cache-Control: max-age=600  
> Content-Length: 18419

Note:  
Expires \< Date + Cache-Control max-age.

The difference is about 2 days, so it looks like  
proxy\_ignore\_headers works as it should.

I suppose previously you’ve looked at files cached without  
proxy\_ignore\_headers in config. Note that changing config isn’t  
enough to get longer cache valid times for already cached  
responses, since validity time is calculated while obtaining  
response from a backend. A response have to be recached with the  
new settings.

A side note: you may want to hide or change Expires header to  
make sure clients will be able to cache responses. This may be  
done either with proxy\_hide\_header or with “expires” directive.

Maxim D.

---

<div class="post-metadata">

**Author:** ![piotr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@piotr](https://www.ruby-forum.com/u/piotr)\
**Post date:** [December 17, 2011, 4:19pm UTC](https://www.ruby-forum.com/t/proxy-ignore-headers-doesnt-seem-to-work/214879/4 "2011-12-17T16:19:48Z")

</div>

Maxim D. Wrote:

> Try “nginx -t”. If it doesn’t help, please post  
> the full config  
> you’re testing with.

Hi,

Maxim, thank you for your response!

I’ve checked both servers for config errors before, but without any  
clues.

nginx -t  
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  
nginx: configuration file /etc/nginx/nginx.conf test is successful

Current configuration:

\*\*\*\*\* cat /etc/nginx/nginx.conf

user nginx;  
worker\_processes 1;

error\_log /var/log/nginx/error.log warn;  
pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;

```
log_format main '$remote_addr - $remote_user [$time_local]

```

“$request” ’  
'$status $body\_bytes\_sent “$http\_referer” ’  
‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;

```
access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 5;

#gzip on;

include /etc/nginx/conf.d/*.conf;

```

}

\*\*\*\*\* cat /etc/nginx/conf.d/proxy.conf

log\_format cache '$remote\_addr $time\_local ’  
'$upstream\_cache\_status ’  
'proxy\_host:$proxy\_host ’  
'Cache-Control:$upstream\_http\_cache\_control ’  
'Expires:$upstream\_http\_expires ’  
'upstream\_server:$upstream\_addr ’  
'upstream\_status:$upstream\_status ’  
'“$request” ($status) ’  
'“$http\_user\_agent” ';

proxy\_cache\_path /home/mpqcache levels=1:2:2  
keys\_zone=mpqcache:30000m;

upstream mpq\_cluster {  
#ip\_hash;  
server otile1.mqcdn.com:80;  
server otile2.mqcdn.com:80;  
server otile3.mqcdn.com:80;  
server otile4.mqcdn.com:80;  
}

server {

```
listen 80;
server_name mpq1.XXX.com mpq2.XXX.com;

access_log /var/log/nginx/mpq1.XXX.com_access.log cache;
error_log /var/log/nginx/mpq1.XXX.com_error.log info;

location / {
  #proxy_pass http://mpq_cluster;
  proxy_pass http://otile1.mqcdn.com;
  proxy_set_header Host otile1.mqcdn.com;
  proxy_ignore_headers X-Accel-Expires Expires Cache-Control

```

Set-Cookie;  
proxy\_cache mpqcache;  
proxy\_cache\_key “$scheme$host$request\_uri”;  
proxy\_cache\_valid 200 302 600h;  
proxy\_cache\_valid any 90m;  
}

} # server

\*\*\*\*\* sample headers from upstream server:

[http://otile3.mqcdn.com/tiles/1.0.0/osm/15/5240/12661.jpg](http://otile3.mqcdn.com/tiles/1.0.0/osm/15/5240/12661.jpg)

GET /tiles/1.0.0/osm/15/5240/12661.jpg HTTP/1.1  
Host: [otile3.mqcdn.com](http://otile3.mqcdn.com)  
User-Agent: Mozilla/5.0 (Ubuntu; X11; Linux i686; rv:8.0) Gecko/20100101  
Firefox/8.0  
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8  
Accept-Language: en,en-us;q=0.7,pl;q=0.3  
Accept-Encoding: gzip, deflate  
Accept-Charset: ISO-8859-2,utf-8;q=0.7,\*;q=0.7  
Connection: keep-alive  
If-Modified-Since: Tue, 13 Dec 2011 06:16:41 GMT

HTTP/1.1 304 Not Modified  
Content-Type: image/jpeg  
Expires: Fri, 16 Dec 2011 14:16:45 GMT  
Last-Modified: Tue, 13 Dec 2011 06:16:41 GMT  
Cache-Control: max-age=600  
Date: Fri, 16 Dec 2011 14:06:45 GMT  
Connection: keep-alive

\*\*\*\*\* sample headers from nginx proxy  
[http://mpq1.XXX.com/tiles/1.0.0/osm/15/5240/12661.jpg](http://mpq1.XXX.com/tiles/1.0.0/osm/15/5240/12661.jpg)

GET /tiles/1.0.0/osm/15/5240/12661.jpg HTTP/1.1  
Host: [mpq1.XXX.com](http://mpq1.XXX.com)  
User-Agent: Mozilla/5.0 (Ubuntu; X11; Linux i686; rv:8.0) Gecko/20100101  
Firefox/8.0  
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8  
Accept-Language: en,en-us;q=0.7,pl;q=0.3  
Accept-Encoding: gzip, deflate  
Accept-Charset: ISO-8859-2,utf-8;q=0.7,\*;q=0.7  
Connection: keep-alive  
Cookie: bblastvisit=1323941196; bblastactivity=0;  
\_\_qca=P0-811271075-1323941200190;  
\_\_utma=26892847.397077741.1323941200.1323964564.1324035857.4;  
\_\_utmz=26892847.1323941200.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);  
bbuserid=33280; bbpassword=be7f8ba39107f78fb42020ad76ca953b;  
\_\_utmc=26892847; bbsessionhash=0d7cdd74637b9f503c4f33d7ad1f8394

HTTP/1.1 200 OK  
Server: nginx/1.0.10  
Date: Fri, 16 Dec 2011 14:08:43 GMT  
Content-Type: image/jpeg  
Connection: keep-alive  
Expires: Wed, 14 Dec 2011 14:59:21 GMT  
Last-Modified: Tue, 13 Dec 2011 06:16:41 GMT  
Cache-Control: max-age=600  
Content-Length: 18419

Thanks!

Regards,  
P.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,220058,220164#msg-220164](http://forum.nginx.org/read.php?2,220058,220164#msg-220164)

---

<div class="post-metadata">

**Author:** ![piotr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@piotr](https://www.ruby-forum.com/u/piotr)\
**Post date:** [January 4, 2012, 11:26pm UTC](https://www.ruby-forum.com/t/proxy-ignore-headers-doesnt-seem-to-work/214879/5 "2012-01-04T23:26:28Z")

</div>

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,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![piotr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@piotr](https://www.ruby-forum.com/u/piotr)\
**Post date:** [January 5, 2012, 12:14am UTC](https://www.ruby-forum.com/t/proxy-ignore-headers-doesnt-seem-to-work/214879/6 "2012-01-05T00:14:03Z")

</div>

On Wed, Jan 04, 2012 at 10:26:05PM +0000, Francis D. wrote:

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

Hi there,

One more thing on the final “600s”…

> > 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 don’t specify “inactive” in your proxy\_cache\_path directive, so it  
defaults to 10 minutes.

If you see one new request per url every 11 minutes, then it is expected  
that nginx will re-fetch from upstream each time.

If you see a new request every 9 minutes, then nginx should not need to  
re-fetch from upstream.

Does that explain what you see?

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![piotr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@piotr](https://www.ruby-forum.com/u/piotr)\
**Post date:** [January 4, 2012, 9:12pm UTC](https://www.ruby-forum.com/t/proxy-ignore-headers-doesnt-seem-to-work/214879/7 "2012-01-04T21:12:53Z")

</div>

Maxim,

Sorry for the late response.

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;  
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.

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. 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.

[http://mpq1.XXX.com/tiles/1.0.0/osm/12/1035/1519.jpg](http://mpq1.XXX.com/tiles/1.0.0/osm/12/1035/1519.jpg)

GET /tiles/1.0.0/osm/12/1035/1519.jpg HTTP/1.1  
Host: [mpq1.XXX.com](http://mpq1.XXX.com)  
User-Agent: Mozilla/5.0 (Ubuntu; X11; Linux i686; rv:9.0.1)  
Gecko/20100101 Firefox/9.0.1  
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8  
Accept-Language: en,en-us;q=0.7,pl;q=0.3  
Accept-Encoding: gzip, deflate  
Accept-Charset: ISO-8859-2,utf-8;q=0.7,\*;q=0.7  
Connection: keep-alive  
Cookie: bblastvisit=1325618979; bblastactivity=0;  
\_\_utma=26892847.843027784.1325618982.1325618982.1325703951.2;  
\_\_utmz=26892847.1325618982.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);  
\_\_qca=P0-367095175-1325618982208;  
bbsessionhash=02acddda9354e88dd04bab92358aeca6; \_\_utmc=26892847

HTTP/1.1 200 OK  
Server: nginx/1.0.11  
Date: Wed, 04 Jan 2012 19:52:01 GMT  
Content-Type: image/jpeg  
Connection: keep-alive  
Content-Length: 8010  
Cache-Control: max-age=600  
Last-Modified: Wed, 04 Jan 2012 02:18:15 GMT  
Expires: Wed, 04 Jan 2012 20:02:01 GMT

Regards,  
Piotr

Posted at Nginx Forum:

> **[Re: proxy\_ignore\_headers doesn't seem to work](https://forum.nginx.org/read.php?2,220058,220808#msg-220808)**
>
> Hello, I've problem similar as in this thread: http://mailman.nginx.org/pipermail/nginx/2010-May/020349.html nginx is ignoring my proxy\_cache\_valid value, using instead expire time specified by upstream server. proxy\_ignore\_headers X-Accel-Expires Ex

---

<div class="post-metadata">

**Author:** ![piotr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@piotr](https://www.ruby-forum.com/u/piotr)\
**Post date:** [January 9, 2012, 7:51pm UTC](https://www.ruby-forum.com/t/proxy-ignore-headers-doesnt-seem-to-work/214879/8 "2012-01-09T19:51:00Z")

</div>

Maxim,

Yes, i’ve missed this “inactive” param - unfortunately expire time from  
upstream server was the same as default inactive value, with was  
misleading for me.

May I suggest to add additional info about this inactive param to  
[Module ngx\_http\_proxy\_module](http://wiki.nginx.org/HttpProxyModule#proxy_cache_valid) page?

Thank you for your help!

Regards,  
p.

Posted at Nginx Forum:

> **[Re: proxy\_ignore\_headers doesn't seem to work](https://forum.nginx.org/read.php?2,220058,220972#msg-220972)**
>
> Hello, I've problem similar as in this thread: http://mailman.nginx.org/pipermail/nginx/2010-May/020349.html nginx is ignoring my proxy\_cache\_valid value, using instead expire time specified by upstream server. proxy\_ignore\_headers X-Accel-Expires Ex

---

<div class="post-metadata">

**Author:** ![piotr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@piotr](https://www.ruby-forum.com/u/piotr)\
**Post date:** [January 5, 2012, 4:19am UTC](https://www.ruby-forum.com/t/proxy-ignore-headers-doesnt-seem-to-work/214879/9 "2012-01-05T04:19:21Z")

</div>

Hello!

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

> 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.

You don’t hide the headers, and don’t set headers in config. The  
proxy\_ignore\_headers instruct nginx to ignore headers in question  
(i.e. don’t set/limit cache validity time as stored in cache  
metadata based on these headers). The proxy\_cache\_valid  
directives set cache validity times. None of these directives  
hide or modify headers in question.

To hide headers, you have to use the proxy\_hide\_header directive  
(as already suggested in previous message), see here for details:

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_hide_header)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

To explicitly set Cache-Control/Expires headers, use the “expires”  
directive, see here for details:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

(no official docs in English yet)

> 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. 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.

Do you request the file in question with interval larger than 600  
seconds, without any intermediate requests? It is expected to be  
removed from cache as inactive one in such test, see desciption of  
the “inactive” parameter of the “proxy\_cache\_path” directive here:

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_path)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

Try requesting a file once per minute to keep it active.

Maxim D.
