Purge the Nginx cache
Francis Daly
francis at daoine.org
Tue May 3 11:57:11 UTC 2022
On Tue, May 03, 2022 at 03:59:48PM +0530, Kaushal Shriyan wrote:
Hi there,
> I am following https://bluegrid.io/edu/how-to-purge-the-nginx-cache/ and
> have attached the nginx config file for your reference. I am running nginx
> version: nginx/1.20.2 on CentOS Linux release 7.9.2009 (Core)
>
> #curl -I https://testnginxproxycachepurge.testintcraft.com -H 'Cache-Purge:
> true'
> HTTP/1.1 200 OK
> *X-Cache-Status: HIT*
>
> Please guide me. Thanks in advance.
You made a curl request for https://testnginxproxycachepurge.testintcraft.com.
Your config for that request (location /) includes
proxy_cache_bypass $bypass;
proxy_cache_bypass $no_cache $nouricache;
Each of those variables is 0 or empty, so "X-Cache-Status: HIT"
is correct.
If you want to bypass the cache, you must make at least one of those
variables have a different value.
For local testing, you could try adding something like
map $http_cache_purge $bypass {
default 0;
true 1;
}
beside your other "map" directives; but you should understand what
that does, and how it compares to what you want, before running it
in production.
If there are follow-up questions, it might be worth explaining what
exactly it is that you want to achieve.
The "normal" nginx behaviour when caching is enabled, is: a request comes
from the client; nginx looks in the cache to see if it has a response
for that that request that is still valid; if there is a valid response,
nginx writes it to the client; if there is not a valid response, nginx
makes a request of upstream, gets the response, writes it to the cache
with a suitable "valid" time, and writes it to the client.
Pretty much every step of that can be changed by configuration.
I *think* that the thing that you want to do is: for some specific
requests, instead of nginx sending a valid response from its cache,
nginx should make a request of upstream and write the new response to
the cache (as well as sending it to the client).
If that is not it -- or if you want to give a more specific description
of "some specific requests" -- then adding the details will help other
people to be able to provide a good answer.
Good luck with it,
f
--
Francis Daly francis at daoine.org
More information about the nginx
mailing list