# FastCGI cache has stopped working

**URL:** <https://www.ruby-forum.com/t/fastcgi-cache-has-stopped-working/227073>\
**Category:** NGINX\
**Created:** [March 3, 2013, 1:32pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-has-stopped-working/227073 "2013-03-03T13:32:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel15](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecccb3/32.png) [@Daniel15](https://www.ruby-forum.com/u/Daniel15)\
**Post date:** [March 3, 2013, 1:32pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-has-stopped-working/227073/1 "2013-03-03T13:32:43Z")

</div>

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/](http://dan.cx/), and here is my Nginx configuration for  
this  
site: [https://github.com/Daniel15/Website/blob/master/nginx.conf](https://github.com/Daniel15/Website/blob/master/nginx.conf)

Thanks!

Posted at Nginx Forum:

> **[FastCGI cache has stopped working](https://forum.nginx.org/read.php?2,236852,236852#msg-236852)**
>
> 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;...

---

<div class="post-metadata">

**Author:** ![Daniel15](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecccb3/32.png) [@Daniel15](https://www.ruby-forum.com/u/Daniel15)\
**Post date:** [March 3, 2013, 1:45pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-has-stopped-working/227073/2 "2013-03-03T13:45:34Z")

</div>

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:

> **[Re: FastCGI cache has stopped working](https://forum.nginx.org/read.php?2,236852,236855#msg-236855)**
>
> 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;...

---

<div class="post-metadata">

**Author:** ![Daniel15](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecccb3/32.png) [@Daniel15](https://www.ruby-forum.com/u/Daniel15)\
**Post date:** [March 3, 2013, 1:57pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-has-stopped-working/227073/3 "2013-03-03T13:57:51Z")

</div>

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/](http://dan.cx/), and here is my Nginx configuration for this  
> site: [https://github.com/Daniel15/Website/blob/master/nginx.conf](https://github.com/Daniel15/Website/blob/master/nginx.conf)

Generic debugging hints are here:

> **[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

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.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Daniel15](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecccb3/32.png) [@Daniel15](https://www.ruby-forum.com/u/Daniel15)\
**Post date:** [March 3, 2013, 2:03pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-has-stopped-working/227073/4 "2013-03-03T14:03:07Z")

</div>

## 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](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](http://trac.nginx.org/nginx/ticket/310)

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

---

<div class="post-metadata">

**Author:** ![Daniel15](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecccb3/32.png) [@Daniel15](https://www.ruby-forum.com/u/Daniel15)\
**Post date:** [March 3, 2013, 2:06pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-has-stopped-working/227073/5 "2013-03-03T14:06:02Z")

</div>

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:

> **[RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 | RFC Editor](https://www.rfc-editor.org/info/rfc2616/)**
>
> HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification defines the protocol referred to as "HTTP/1.1", and is an update to RFC 2068. \[STANDARDS-TRACK\]

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Daniel15](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecccb3/32.png) [@Daniel15](https://www.ruby-forum.com/u/Daniel15)\
**Post date:** [March 3, 2013, 2:07pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-has-stopped-working/227073/6 "2013-03-03T14:07:48Z")

</div>

Hello!

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

> Try [http://dan.cx/bundles/main.css](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](http://trac.nginx.org/nginx/ticket/310)

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

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Daniel15](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecccb3/32.png) [@Daniel15](https://www.ruby-forum.com/u/Daniel15)\
**Post date:** [March 4, 2013, 12:53pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-has-stopped-working/227073/7 "2013-03-04T12:53:24Z")

</div>

## 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 | RFC Editor](http://tools.ietf.org/html/rfc2616#section-3.3.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](https://bugzilla.xamarin.com/show_bug.cgi?id=10872)

Gotta love open source software 🙂

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