Refresh cached pages in NGINX

Here’s a quick tidbit for forcing individual pages to refresh on an nginx reverse caching server.

In your SERVER block put:


if ($request_uri ~* "^/cache-refresh/(.*)") {
set $cache_bypass 1;
rewrite ^(/cache-refresh/)(.*)$ /$2 last;
}

and in your LOCATION block(s), add:


location / {
proxy_cache_bypass $cache_bypass; # Do not serve response from cache.
proxy_cache staticfilecache;
proxy_pass http://backendsite;
}

There are numerous other helpful directives as well. But if you’re looking for a way to refresh your cached pages individually, this should be enough to help you in the right direction.

One thought on “Refresh cached pages in NGINX

  1. I like W3TC quite a lot, but I found it to be finicky and somewhat a pain to administer – especially in a multi-site environment. That’s why I opted for a front-end reverse caching proxy server using NGINX and didn’t install any caching on WP itself (although a layered approach incorporating both W3TC and a reverse caching proxy would be the best setup for a single blog – especially if it’s high traffic). You can find more info on setting up NGINX as a reverse-caching proxy server at: http://wordpress.org/extend/plugins/nginx-proxy-cache-integrator/ . The notes in this post allow you to add rules to manually update individual pages rather than waiting for the timeouts to expire. It’s handy when you need to update pages, CSS, or theme elements and want to make sure it all looks OK without waiting.

    If you need specific help, we at dm42.net can offer some consulting – either to guide you in the right direction or to actually set it up for you. If you’re interested, send feedback through the web-form or call the number listed on the site.