<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 3, 2022 at 5:30 PM Francis Daly <<a href="mailto:francis@daoine.org">francis@daoine.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, May 03, 2022 at 03:59:48PM +0530, Kaushal Shriyan wrote:<br>
<br>
Hi there,<br>
<br>
> I am following <a href="https://bluegrid.io/edu/how-to-purge-the-nginx-cache/" rel="noreferrer" target="_blank">https://bluegrid.io/edu/how-to-purge-the-nginx-cache/</a> and<br>
> have attached the nginx config file for your reference. I am running nginx<br>
> version: nginx/1.20.2 on CentOS Linux release 7.9.2009 (Core)<br>
> <br>
> #curl -I <a href="https://testnginxproxycachepurge.testintcraft.com" rel="noreferrer" target="_blank">https://testnginxproxycachepurge.testintcraft.com</a> -H 'Cache-Purge:<br>
> true'<br>
> HTTP/1.1 200 OK<br>
> *X-Cache-Status: HIT*<br>
> <br>
> Please guide me. Thanks in advance.<br>
<br>
You made a curl request for <a href="https://testnginxproxycachepurge.testintcraft.com" rel="noreferrer" target="_blank">https://testnginxproxycachepurge.testintcraft.com</a>.<br>
<br>
Your config for that request (location /) includes<br>
<br>
proxy_cache_bypass $bypass;<br>
proxy_cache_bypass $no_cache $nouricache;<br>
<br>
Each of those variables is 0 or empty, so "X-Cache-Status: HIT"<br>
is correct.<br>
<br>
If you want to bypass the cache, you must make at least one of those<br>
variables have a different value.<br>
<br>
For local testing, you could try adding something like<br>
<br>
map $http_cache_purge $bypass {<br>
default 0;<br>
true 1;<br>
}<br>
<br>
beside your other "map" directives; but you should understand what<br>
that does, and how it compares to what you want, before running it<br>
in production.<br>
<br>
<br>
<br>
If there are follow-up questions, it might be worth explaining what<br>
exactly it is that you want to achieve.<br>
<br>
The "normal" nginx behaviour when caching is enabled, is: a request comes<br>
from the client; nginx looks in the cache to see if it has a response<br>
for that that request that is still valid; if there is a valid response,<br>
nginx writes it to the client; if there is not a valid response, nginx<br>
makes a request of upstream, gets the response, writes it to the cache<br>
with a suitable "valid" time, and writes it to the client.<br>
<br>
Pretty much every step of that can be changed by configuration.<br>
<br>
I *think* that the thing that you want to do is: for some specific<br>
requests, instead of nginx sending a valid response from its cache,<br>
nginx should make a request of upstream and write the new response to<br>
the cache (as well as sending it to the client).<br>
<br>
If that is not it -- or if you want to give a more specific description<br>
of "some specific requests" -- then adding the details will help other<br>
people to be able to provide a good answer.<br>
<br>
Good luck with it,<br>
<br>
f<br>
-- <br>
Francis Daly <a href="mailto:francis@daoine.org" target="_blank">francis@daoine.org</a><br>
_______________________________________________<br>
nginx mailing list -- <a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
To unsubscribe send an email to <a href="mailto:nginx-leave@nginx.org" target="_blank">nginx-leave@nginx.org</a></blockquote><div><br></div><div>Thanks Francis for the detailed explanation and much appreciated !!!. We typically clear the nginx cache manually using the below command.</div><div><br></div><div>#rm -rf /var/www/nginx/cache/content/*</div><div>#rm -rf /var/www/nginx/cache/files/*</div><div><br></div><div>The bigger problem is that this way of purging the Nginx cache deletes everything that was cached by this Nginx reverse proxy server and adds overhead to the infrastructure impacting the performance resulting with a high number of requests per time unit.<br></div><div>I am trying out by purging with the BYPASS method as Nginx module proxy_cache_purge needs commercial subscription. <br></div><div><br></div><div>Directive proxy_cache_bypass is a recommended approach to refresh the cache resource after successful retrieval of the contents from the upstream backend server.</div><div><br></div><div>I have deleted the cache by following the method</div><div><br></div><div><div>#rm -rf /var/www/nginx/cache/content/*</div><div>#rm -rf /var/www/nginx/cache/files/*</div></div><div>#curl -I <a href="https://testnginxproxycachepurge.testintcraft.com">https://testnginxproxycachepurge.testintcraft.com</a> -H 'Cache-Purge: true'<br>HTTP/1.1 200 OK<br>Server: nginx/1.20.2<br>Date: Tue, 03 May 2022 16:06:08 GMT<br>Content-Type: text/html; charset=UTF-8<br>Connection: keep-alive<br>Cache-Control: max-age=21600, public<br>Link: <<a href="https://testnginxproxycachepurge.testintcraft.com/">https://testnginxproxycachepurge.testintcraft.com/</a>>; rel="canonical", <<a href="https://testnginxproxycachepurge.testintcraft.com/">https://testnginxproxycachepurge.testintcraft.com/</a>>; rel="shortlink", <<a href="https://testnginxproxycachepurge.testintcraft.com/home">https://testnginxproxycachepurge.testintcraft.com/home</a>>; rel="revision"<br>X-UA-Compatible: IE=edge<br>Content-language: en<br>X-Content-Type-Options: nosniff<br>X-Frame-Options: SAMEORIGIN<br>Permissions-Policy: interest-cohort=()<br>Expires: Sun, 19 Nov 1978 05:00:00 GMT<br>Vary: Cookie<br>X-XSS-Protection: 1; mode=block<br>Strict-Transport-Security: max-age=31536000; includeSubDomains<br>Set-Cookie: ADRUM_BT=R%3A0%7Cg%3A39ca00fc-b183-4fbf-95ad-494a6e7b8d1f102%7Cn%3Aicebergtest_e1c60ae6-5d00-47d5-8c0a-690d8465795f%7Ci%3A129601%7Cs%3Af; expires=Tue, 03-May-2022 16:06:38 GMT; Max-Age=30; path=/<br>Last-Modified: Tue, 26 Apr 2022 11:42:25 GMT<br>ETag: "1650973345"<br>Access-Control-Allow-Origin: *<br><b>X-Cache-Status: MISS<br></b><br>#curl -I <a href="https://testnginxproxycachepurge.testintcraft.com">https://testnginxproxycachepurge.testintcraft.com</a> -H 'Cache-Purge: true'<br>HTTP/1.1 200 OK<br>Server: nginx/1.20.2<br>Date: Tue, 03 May 2022 16:06:19 GMT<br>Content-Type: text/html; charset=UTF-8<br>Connection: keep-alive<br>Cache-Control: max-age=21600, public<br>Link: <<a href="https://testnginxproxycachepurge.testintcraft.com/">https://testnginxproxycachepurge.testintcraft.com/</a>>; rel="canonical", <<a href="https://testnginxproxycachepurge.testintcraft.com/">https://testnginxproxycachepurge.testintcraft.com/</a>>; rel="shortlink", <<a href="https://testnginxproxycachepurge.testintcraft.com/home">https://testnginxproxycachepurge.testintcraft.com/home</a>>; rel="revision"<br>X-UA-Compatible: IE=edge<br>Content-language: en<br>X-Content-Type-Options: nosniff<br>X-Frame-Options: SAMEORIGIN<br>Permissions-Policy: interest-cohort=()<br>Expires: Sun, 19 Nov 1978 05:00:00 GMT<br>Vary: Cookie<br>X-XSS-Protection: 1; mode=block<br>Strict-Transport-Security: max-age=31536000; includeSubDomains<br>Set-Cookie: ADRUM_BT=R%3A0%7Cg%3A39ca00fc-b183-4fbf-95ad-494a6e7b8d1f102%7Cn%3Aicebergtest_e1c60ae6-5d00-47d5-8c0a-690d8465795f%7Ci%3A129601%7Cs%3Af; expires=Tue, 03-May-2022 16:06:38 GMT; Max-Age=30; path=/<br>Last-Modified: Tue, 26 Apr 2022 11:42:25 GMT<br>ETag: "1650973345"<br>Access-Control-Allow-Origin: *<br><b>X-Cache-Status: HIT<br></b>#<br></div><div><br></div><div>I am seeing it as HIT instead of BYPASS in context to Nginx cache. I am attaching the config file for your reference. Please comment and I look forward to hearing from you. Thanks in Advance.</div><div><br></div><div>Best Regards,</div><div><br></div><div>Kaushal</div></div></div>