# Proxy\_cache\_use\_stale updating and X-Accel-Expires=0

**URL:** <https://www.ruby-forum.com/t/proxy-cache-use-stale-updating-and-x-accel-expires-0/191960>\
**Category:** NGINX\
**Created:** [July 21, 2010, 11:07am UTC](https://www.ruby-forum.com/t/proxy-cache-use-stale-updating-and-x-accel-expires-0/191960 "2010-07-21T11:07:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JSSSSrSSSSme\_Loyet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee59a6/32.png) [@JSSSSrSSSSme\_Loyet](https://www.ruby-forum.com/u/JSSSSrSSSSme_Loyet)\
**Post date:** [July 21, 2010, 11:07am UTC](https://www.ruby-forum.com/t/proxy-cache-use-stale-updating-and-x-accel-expires-0/191960/1 "2010-07-21T11:07:43Z")

</div>

Hi,

I have a strange situation. I don’t really know if it’s a bug or a  
feature.

I’m using nginx as a cached reverse proxy to apache/mod\_php.

I have the following (simplified) conf:

proxy\_cache\_use\_stale updating error timeout invalid\_header http\_500  
http\_502 http\_503 http\_504;  
proxy\_cache\_key $scheme$host$request\_uri$args;  
proxy\_cache\_path /CACHE levels=1:2:2 keys\_zone=cache:256m inactive=1d  
max\_size=20g;  
proxy\_no\_cache $http\_authorization;  
proxy\_ignore\_headers Expires Cache-Control;

upstream backend.www {  
server www0:9001;  
server www1:9001;  
server www2:9001;  
server www3:9001;  
server www4:9001;  
server www5:9001;  
server www6:9001;  
server www7:9001;  
server www8:9001;  
server www9:9001;  
}

server {  
listen 80;  
location / {  
proxy\_cache\_valid 200 301 302 404 500 5m;  
proxy\_cache\_valid any 1m;  
proxy\_pass [http://backend.www](http://backend.www);  
}  
}

Some pages returns the X-Accel-Expires=0 header to exclude a page from  
the cache. It works great. But sometimes, nginx returns those page  
with a 404 response without fetching the page to the backend server.  
Those pages are marked as UPDATING in logs.

How a page excluded from the cache can be wrongly (404 instead of 200)  
served by the cache with an UPDATING status ?

Here are extracts of my logs.

XXXXXX - - [16/Jul/2010:11:18:36 +0200] “GET  
/index\_favoris.php?cid=52440 HTTP/1.1” 200 1403  
“[http://www.foo.bar/cid52440/](http://www.foo.bar/cid52440/)” “” “4.74” 0.099 X-Accel-Expires=0  
10.26.49.22:9004,200,0.099,MISS ← it works

XXXXXX - - [16/Jul/2010:11:24:55 +0200] “GET  
/index\_favoris.php?cid=52440 HTTP/1.0” 404 3076  
“[http://www.foo.bar/cid52440/](http://www.foo.bar/cid52440/)” “” “-” 0.000 X-Accel-Expires=-  
-,-,-,UPDATING ← doesn’t work

XXXXXX - - [16/Jul/2010:11:32:15 +0200] “GET  
/index\_favoris.php?cid=52440 HTTP/1.0” 404 3076  
“[http://www.foo.bar/cid52440/](http://www.foo.bar/cid52440/)” “” “-” 0.000 X-Accel-Expires=-  
-,-,-,UPDATING ← doesn’t work

Thx for your replies

++ Jerome

---

<div class="post-metadata">

**Author:** ![JSSSSrSSSSme\_Loyet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee59a6/32.png) [@JSSSSrSSSSme\_Loyet](https://www.ruby-forum.com/u/JSSSSrSSSSme_Loyet)\
**Post date:** [July 21, 2010, 11:29am UTC](https://www.ruby-forum.com/t/proxy-cache-use-stale-updating-and-x-accel-expires-0/191960/2 "2010-07-21T11:29:58Z")

</div>

Le 21 juillet 2010 11:06, Jérôme Loyet [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) a écrit :

> proxy\_cache\_key $scheme$host$request\_uri$args;  
> server www4:9001;  
> proxy\_cache\_valid 200 301 302 404 500 5m;  
> How a page excluded from the cache can be wrongly (404 instead of 200)  
> XXXXXX - - [16/Jul/2010:11:24:55 +0200] “GET  
> /index\_favoris.php?cid=52440 HTTP/1.0” 404 3076  
> “[http://www.foo.bar/cid52440/](http://www.foo.bar/cid52440/)” “” “-” 0.000 X-Accel-Expires=-  
> -,-,-,UPDATING ← doesn’t work
> 
> XXXXXX - - [16/Jul/2010:11:32:15 +0200] “GET  
> /index\_favoris.php?cid=52440 HTTP/1.0” 404 3076  
> “[http://www.foo.bar/cid52440/](http://www.foo.bar/cid52440/)” “” “-” 0.000 X-Accel-Expires=-  
> -,-,-,UPDATING ← doesn’t work
> 
> Thx for your replies

btw I forgot to specified the nginx version I’m using: 0.8.41

---

<div class="post-metadata">

**Author:** ![JSSSSrSSSSme\_Loyet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee59a6/32.png) [@JSSSSrSSSSme\_Loyet](https://www.ruby-forum.com/u/JSSSSrSSSSme_Loyet)\
**Post date:** [July 30, 2010, 11:51pm UTC](https://www.ruby-forum.com/t/proxy-cache-use-stale-updating-and-x-accel-expires-0/191960/3 "2010-07-30T23:51:09Z")

</div>

Hello!

On Wed, Jul 21, 2010 at 11:06:26AM +0200, JÃ©rÃ´me Loyet wrote:

> I have a strange situation. I don’t really know if it’s a bug or a feature.
> 
> I’m using nginx as a cached reverse proxy to apache/mod\_php.
> 
> I have the following (simplified) conf:
> 
> proxy\_cache\_use\_stale updating error timeout invalid\_header http\_500  
> http\_502 http\_503 http\_504;

[…]

> Some pages returns the X-Accel-Expires=0 header to exclude a page from  
> the cache. It works great. But sometimes, nginx returns those page  
> with a 404 response without fetching the page to the backend server.  
> Those pages are marked as UPDATING in logs.

Directive proxy\_cache\_use\_stale set to “updating” instructs nginx  
to return stale cached response if one request to the same uri  
is already goes to backend.

> How a page excluded from the cache can be wrongly (404 instead of 200)  
> served by the cache with an UPDATING status ?

Looks like you happen to have stale document with 404 status in  
cache (e.g. cached during debugging). It’s not expunged from  
cache as it’s active (i.e. frequently requested), and not updated  
in cache as you return X-Accel-Expires=0 in responses.

But it’s in cache, and once you get more than one simulteneous  
request to this document - nginx returns stale response from cache  
as it was said to.

Maxim D.

---

<div class="post-metadata">

**Author:** ![JSSSSrSSSSme\_Loyet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee59a6/32.png) [@JSSSSrSSSSme\_Loyet](https://www.ruby-forum.com/u/JSSSSrSSSSme_Loyet)\
**Post date:** [July 31, 2010, 12:06am UTC](https://www.ruby-forum.com/t/proxy-cache-use-stale-updating-and-x-accel-expires-0/191960/4 "2010-07-31T00:06:23Z")

</div>

2010/7/30 Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > 
> 
> Directive proxy\_cache\_use\_stale set to “updating” instructs nginx
> 
> But it’s in cache, and once you get more than one simulteneous  
> request to this document - nginx returns stale response from cache  
> as it was said to.

the page always return X-Accel-Expires=0, should it not be recorded in  
the cache ?
