In our checklist for perfect WordPress-Nginx setup, we have a section dedicated to check if page-caching will work in case PHP/MySQL backend crash. Some readers did not like my way of actually shutting down PHP backend for cache-verification.
If you are using Nginx’s
fastcgi_cache, then you can use
upstream_cache_status variable to test cache for particular URLs without shutting down PHP.
All you need to do is, add a line like below to
/etc/nginx/nginx.conf file, in
add_header rt-Fastcgi-Cache $upstream_cache_status;
Just reload nginx config:
service nginx reload
Check HTTP response for any page and you will see something like:
HTTP/1.1 200 OK Server: nginx Date: Fri, 26 Jul 2013 15:38:51 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Vary: Accept-Encoding X-Powered-By: PHP/5.4.17-1~precise+1 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache X-Pingback: http://rtcamp.com/xmlrpc.php rt-Fastcgi-Cache: HIT
Please note last line. Value next to rt-Fastcgi-Cache indicates fastcgi-cache status.
If you see a MISS, send similar request again and it should get you a HIT.
If you see BYPASS, that means some conditions for skipping cache are met.
Related: Using $upstream_cache_status improving cache efficiency
Thanks, that neatly answers my question: http://rtcamp.com/groups/wordpress-nginx/forum/topic/caching-issues/
BTW. you have a dead-link in this article, at the bottom of it it says:
“Related: Using for $upstream_cache_status improving cache efficiency” and the link gives a 404 error.
Thanks. Fixed broken link. 🙂
Dumb question: How do I “check HTTP response for any page”?
You can use CURL command or an online tool like this – http://web-sniffer.net/
I get BYPASS for all pages except homepage. Why? I’ve followed your tutorial to set up fastcgi on LNMP
My site url looks like: http://domain/index.php/2013/10/postname/
Use nginx-helper plugin to remove index.php from permalinks – http://wordpress.org/plugins/nginx-helper/
index.phpin URL is reason for cache getting BYPASS.
Also, you may need to save your wordpress-permalinks again after activating nginx-helper. Though you don’t need to make any changes in nginx-helper as activating it is enough to remove
Now I get HIT, but there’s no following like output in the page source:
Both are different thing. HIT in curl output is enough to conclude cache is working properly.
If you want to see HTML comments in output, go to nginx-helper plugin settings and turn on “Enable Nginx Timestamp in HTML” option.