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