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.