How to fix: Nginx proxy or fastcgi cache always MISS or EXPIRED

I've recently had an issue with my Nginx setup: it wasn't caching or serving cached pages properly. Every time I would visit, I'd get "MISS" or "EXPIRED".


What I found online is that you have to instruct Nginx to ignore browser request headers relative to caching, therefore allowing Nginx to determine whether it should serve cache, all by itself.

This is done by inserting the following directive:

# ignore headers to let Nginx control its own cache
fastcgi_ignore_headers Cache-Control Expires;

However, I already had this in my configuration and it wasn't helping.

After investigating the issue, I determined that my PHP scripts were updating cookies at every request. Nginx was forced to execute the PHP scripts via FastCGI (ie. not serving them from cache) because the cookie data had changed. When PHP sets a cookie, Nginx will not hit the cache, which is normal behavior. I wouldn't recommend changing this behavior. What I did is fix my PHP scripts so that they wouldn't update cookies at every request. Once I did that, I started hitting the cache again!


One last thing: if you turn off fastcgi or proxy buffering, caching may not work properly, so make sure buffering is on (it should be on by default).

Comments

Ely setiawan said…
sangat bermanfaat kunjungi http://www.elysetiawan.com/”>blog mas ely

[url=http://www.elysetiawan.com/]mas ely[/url]

[url]http://www.elysetiawan.com/[/url]

[http://www.elysetiawan.com/ kata kunci]

[blog peternakan ely->http://www.elysetiawan.com/]

http://www.elysetiawan.com/”>kata kunci

[peternakan ely|http://www.elysetiawan.com/]

[mahasiswa peternakan ely](http://www.elysetiawan.com/)

“blog peternakan”:http://www.elysetiawan.com/

mahasiswa peternakan (http://www.elysetiawan.com/)
Blogger said…
According to Stanford Medical, It's really the ONLY reason this country's women live 10 years more and weigh 42 lbs less than us.

(And by the way, it has totally NOTHING to do with genetics or some secret-exercise and EVERYTHING to do with "how" they eat.)

P.S, I said "HOW", and not "what"...

Click this link to reveal if this brief questionnaire can help you find out your true weight loss possibilities
Vevenia said…
Thanks for the help..
Anonymous said…
You know your projects stand out of the herd. There is something special about them. It seems to me all of them are really brilliant! how to drag click

Popular posts from this blog

Nginx error 413: Request entity too large Quick Fix

Dealing with Nginx 400 Bad Request HTTP errors

Affiliate module for Interspire Shopping Cart