FastCGI cache has stopped working

Nginx’s FastCGI caching used to work perfectly for me, but recently it
stopped working and I can’t work out why.

This is how the headers look:
HTTP/1.1 200 OK
Server: nginx/1.2.7
Date: Sun, 03 Mar 2013 12:28:24 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 10727
Connection: keep-alive
X-AspNetMvc-Version: 4.0
X-AspNet-Version: 4.0.30319
Expires: Sun, 3 Mar 2013 13:28:24 GMT
Cache-Control: public, max-age=3600
Last-Modified: Sun, 3 Mar 2013 12:26:20 GMT
X-Cache: MISS

It appears that the Last-Modified, Expires and Cache-Control headers are
set
correctly, however the cache status is always “MISS” and the cache
directory
is empty. Any ideas on why this would be happening, and how to debug
this?

The site URL is http://dan.cx/, and here is my Nginx configuration for
this
site: https://github.com/Daniel15/Website/blob/master/nginx.conf

Thanks!

Posted at Nginx Forum:

Figured it out.

The Expires header (“Sun, 3 Mar 2013 13:28:24 GMT”) is using a single
digit
for the date. If I change the “3” to “03”, Nginx works as expected. RFC
1123 and RFC 822 say that both one- and two-digit numbers are valid, so
this
is a bug in Nginx’s caching. I’ll report it to the bug tracker.

Posted at Nginx Forum:

Hello!

On Sun, Mar 03, 2013 at 07:32:05AM -0500, Daniel15 wrote:

X-AspNetMvc-Version: 4.0
The site URL is http://dan.cx/, and here is my Nginx configuration for this
site: https://github.com/Daniel15/Website/blob/master/nginx.conf

Generic debugging hints are here:

In ths particular case I would suggest there is another caching
layer, which results in cached “X-Cache: MISS” being returned.
Note that Expires and Last-Modified are the same, and
X-ExecutionTime headers match exactly:

HTTP/1.1 200 OK
Server: nginx/1.2.7
Date: Sun, 03 Mar 2013 12:49:14 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 10727
Connection: close
X-AspNetMvc-Version: 4.0
X-ExecutionTime: 00:00:00.1373919
X-ExecutionTime: 00:00:00.1717868
X-AspNet-Version: 4.0.30319
Expires: Sun, 3 Mar 2013 13:22:27 GMT
Cache-Control: public, max-age=3600
Last-Modified: Sun, 3 Mar 2013 12:22:27 GMT
X-Cache: MISS

HTTP/1.1 200 OK
Server: nginx/1.2.7
Date: Sun, 03 Mar 2013 12:49:31 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 10727
Connection: close
X-AspNetMvc-Version: 4.0
X-ExecutionTime: 00:00:00.1373919
X-ExecutionTime: 00:00:00.1717868
X-AspNet-Version: 4.0.30319
Expires: Sun, 3 Mar 2013 13:22:27 GMT
Cache-Control: public, max-age=3600
Last-Modified: Sun, 3 Mar 2013 12:22:27 GMT
X-Cache: MISS

HTTP/1.1 200 OK
Server: nginx/1.2.7
Date: Sun, 03 Mar 2013 12:50:25 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 10727
Connection: close
X-AspNetMvc-Version: 4.0
X-ExecutionTime: 00:00:00.1373919
X-ExecutionTime: 00:00:00.1717868
X-AspNet-Version: 4.0.30319
Expires: Sun, 3 Mar 2013 13:22:27 GMT
Cache-Control: public, max-age=3600
Last-Modified: Sun, 3 Mar 2013 12:22:27 GMT
X-Cache: MISS


Maxim D.
http://nginx.org/en/donation.html

Maxim D. Wrote:

In ths particular case I would suggest there is another caching
layer, which results in cached “X-Cache: MISS” being returned.
Note that Expires and Last-Modified are the same, and
X-ExecutionTime headers match exactly:

Yeah, for that particular page there’s another caching layer in the app
itself. The X-Cache header is added by Nginx, however (tested this by
renaming it in my Nginx configuration).

Try http://dan.cx/bundles/main.css instead - This file does not have
another
caching layer, and you can see the Last-Modified and Expires headers
changing on every request.

As far as I can tell, this is a bug in Nginx (looks like it’s not
parsing
the Expires date correctly if the day is a single digit) and I’ve raised
it
in Trac: #310 (FastCGI cache doesn't handle single-digit days correctly) – nginx

Posted at Nginx Forum:

Hello!

On Sun, Mar 03, 2013 at 07:45:21AM -0500, Daniel15 wrote:

Figured it out.

The Expires header (“Sun, 3 Mar 2013 13:28:24 GMT”) is using a single digit
for the date. If I change the “3” to “03”, Nginx works as expected. RFC
1123 and RFC 822 say that both one- and two-digit numbers are valid, so this
is a bug in Nginx’s caching. I’ll report it to the bug tracker.

Nice catch. It’s not a bug in nginx though, as HTTP only allows
fixed-width subset of RFC1123, see here:


Maxim D.
http://nginx.org/en/donation.html

Hello!

On Sun, Mar 03, 2013 at 08:02:45AM -0500, Daniel15 wrote:

Try http://dan.cx/bundles/main.css instead - This file does not have another
caching layer, and you can see the Last-Modified and Expires headers
changing on every request.

As far as I can tell, this is a bug in Nginx (looks like it’s not parsing
the Expires date correctly if the day is a single digit) and I’ve raised it
in Trac: #310 (FastCGI cache doesn't handle single-digit days correctly) – nginx

Closed this as invalid, see my another message for links.


Maxim D.
http://nginx.org/en/donation.html

Maxim D. Wrote:

Nice catch. It’s not a bug in nginx though, as HTTP only allows
fixed-width subset of RFC1123, see here:

RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1

Thanks Maxim! Easy fix. Bug and patch submitted to Mono to fix the date
format used in the headers:
https://bugzilla.xamarin.com/show_bug.cgi?id=10872

Gotta love open source software :slight_smile:

Posted at Nginx Forum: