fastcgi_cache BYPASS when testing for query string


#1

This little snippet from a Wordpress vhost config:

if ($query_string != "") {
	set $skip_cache 1;
}   

Causes every page (except the home page) on the site I’m working on to BYPASS the cache. Here’s what I see in the cache.log:

xx.xx.xx.xxx - BYPASS [10/Feb/2015:17:38:48 -0500]  "GET /services/shared-hosting HTTP/1.1" 200 9709 "http://sandbox.xxxxxxxxxx.com/home-ii/services" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36"

xx.xx.xx.xxx - BYPASS [10/Feb/2015:17:39:24 -0500]  "GET /services/shared-hosting HTTP/1.1" 200 9709 "http://sandbox.xxxxxxxxx.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36"

xx.xx.xx.xxx - BYPASS [10/Feb/2015:17:41:13 -0500]  "GET /contact-us HTTP/1.1" 200 8283 "http://sandbox.xxxxxxxxx.com/services/shared-hosting" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36"

xx.xx.xx.xxx - BYPASS [10/Feb/2015:17:59:16 -0500]  "GET /home-ii/services HTTP/1.1" 200 7924 "http://sandbox.xxxxxxxxx.com/making-technology-work-for-you" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36"

As soon as I comment out the query string test, pages wind up in the cache as you’d expect them to. I admit, I’m stumped. I see no query string in those requests, so the test for “not empty” should fail and $skip_cache should be set to 0.

What am I missing here?


#2

Bump. I am having the same issue.

My Stack: Ubuntu, Nginx with cache-purge module, MariaDB, HHVM

All traffic is also proxied through CloudFlare, maybe that is an issue?

For now, I have this check commented out, but would love to figure out what’s causing this!


#3

I know this is really old, but I was struggling with this too and wanted to post my solution to help others.

In my case, I needed to change

try_files $uri $uri/ /index.php?q=$uri&$args;

(which had been suggested in some DO setup guide) to

try_files $uri $uri/ /index.php?$args;

And bingo, all the subpages started caching and returning hits.