Proxy_cache_use_stale updating and X-Accel-Expires=0

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

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/” “” “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/” “” “-” 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/” “” “-” 0.000 X-Accel-Expires=-
-,-,-,UPDATING <-- doesn’t work

Thx for your replies

++ Jerome

Le 21 juillet 2010 11:06, Jérôme Loyet [email protected] 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/” “” “-” 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/” “” “-” 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

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.

2010/7/30 Maxim D. [email protected]

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 ?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs