FeaturesWP CloudPricingEE CLIContactMy Account

Features

Team Access & User Permissions

Server Setup & Management

Site Creation & Management

Deployments & Developer Tools

Firewall Protection

Speed & Caching

Backups & Recovery

Logs & Monitoring

Create WP Cloud Sites

All Features

Read Documentation

Install

Installation Guide

FAQ

Roadmap

Explore EE CLI

Resources

Commands

Handbook

Blog

Community

Forum

EasyExperts

Tutorials

Subscribe

Github

CLEAR

Start For Free

separator Tutorials separator Nginx separator Adding $upstream_cache_status in HTTP Response Headers

Topics

On this page

Adding $upstream_cache_status in HTTP Response Headers

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’sfastcgi_cache, then you can useupstream_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 http{..} block:


			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

Nginx

PREVIOUS

Amazon Elastic Load Balancer and Forwarding Real-IP Nginx

NEXT


Comments

  1. ovidiu Avatar

    ovidiu

    July 26, 2013

    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.

    1. Rahul Bansal Avatar

      Rahul Bansal

      August 8, 2013

      Thanks. Fixed broken link. 🙂

  2. buzz Avatar

    buzz

    September 29, 2013

    Dumb question: How do I “check HTTP response for any page”?

    1. Rahul Bansal Avatar

      Rahul Bansal

      September 29, 2013

      You can use CURL command or an online tool like this – http://web-sniffer.net/

  3. buzz Avatar

    buzz

    September 29, 2013

    Thanks!

  4. PandaJim Avatar

    PandaJim

    October 30, 2013

    I get BYPASS for all pages except homepage. Why? I’ve followed your tutorial to set up fastcgi on LNMP

    1. PandaJim Avatar

      PandaJim

      October 30, 2013

      My site url looks like: http://domain/index.php/2013/10/postname/

  5. Rahul Bansal Avatar

    Rahul Bansal

    October 30, 2013

    Use nginx-helper plugin to remove index.php from permalinks – http://wordpress.org/plugins/nginx-helper/

    I think index.php in 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 index.php from permalinks.

    1. PandaJim Avatar

      PandaJim

      November 11, 2013

      Now I get HIT, but there’s no following like output in the page source:

      <!-- Dynamic page generated in 0.050 seconds. -->
      <!-- Cached page generated by WP-Super-Cache on 2012-09-14 04:52:06 -->
      <!-- super cache -->
      

      confused.

      1. Rahul Bansal Avatar

        Rahul Bansal

        November 11, 2013

        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.

Features

Useful Links

Product

Other Products

Subscribe for curated product updates, tips, and announcements.

"*" indicates required fields

Facebook

This field is for validation purposes and should be left unchanged.

Email*

Δ


© rtCamp, since 2009. All rights reserved.

Powered by