Welcome! Log In Create A New Profile

Advanced

Re: Purge the Nginx cache

All files from this thread

File Name File Size   Posted by Date  
nginxdefault.conf 5.1 KB open | download kaushalshriyan 04/26/2022 Read message
nginxpurge.conf 5.2 KB open | download kaushalshriyan 04/28/2022 Read message
nginxdefault.conf 5.1 KB open | download kaushalshriyan 05/03/2022 Read message
nginx.conf.bypass 5.4 KB open | download kaushalshriyan 05/03/2022 Read message
Francis Daly
May 04, 2022 09:10AM
On Tue, May 03, 2022 at 09:47:03PM +0530, Kaushal Shriyan wrote:

Hi there,

> Thanks Francis for the detailed explanation and much appreciated !!!. We
> typically clear the nginx cache manually using the below command.
>
> #rm -rf /var/www/nginx/cache/content/*
> #rm -rf /var/www/nginx/cache/files/*

That will remove from the filesystem anything that was in those
directories; that will have the effect of nginx not having a valid
response in the cache for an incoming request, so nginx will make the
request of upstream and handle the response.

> 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.

Yes - that "purge" is "removal of everything from disk".

> Directive proxy_cache_bypass is a recommended approach to refresh the cache
> resource after successful retrieval of the contents from the upstream
> backend server.

Yes - "proxy_cache_bypass" will tell nginx to skip the "looks in the
cache" step of the processing, and just do all of the other steps.

It won't "purge" the cache at all; it will add-or-replace the cached
response for this one request. If that is what you want, then it is the
correct directive to use.

> I have deleted the cache by following the method
>
> #rm -rf /var/www/nginx/cache/content/*
> #rm -rf /var/www/nginx/cache/files/*
> #curl -I https://testnginxproxycachepurge.testintcraft.com -H 'Cache-Purge:
> true'
> HTTP/1.1 200 OK

> *X-Cache-Status: MISS*

> #curl -I https://testnginxproxycachepurge.testintcraft.com -H 'Cache-Purge:
> true'
> HTTP/1.1 200 OK

> *X-Cache-Status: HIT*#

> 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.

You originally had the config that never set $bypass.

I suggested that you set $bypass by adding a "map" to sometimes set
$bypass to 1.

You added the "map", which was good; and then you also added code to
always set $bypass to 0, and then sometimes set it to something else.

So the second piece of code you added, undid what the first piece you
added did.

If you are going to "set $bypass 0;", then you may as well remove the
"map" part again.


What does the nginx access log say about this request? Most importantly:
what is the IP address of the client, as far as nginx is concerned? If
it does not match

$remote_addr ~ "^(127.0.0.1)$"

then your $bypass will remain as 0, and your cache will never be bypassed.

If you want to allow one set of IP addresses to invite nginx to bypass
the cache, put that IP address pattern in the "if $remote_addr" part.

If you want to allow any IP address to invite nginx to bypass the cache,
set $bypass for any IP address.

Good luck with it,

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-leave@nginx.org
Subject Author Posted

Purge the Nginx cache

kaushalshriyan April 22, 2022 12:38PM

Re: Purge the Nginx cache

Sergey A. Osokin April 22, 2022 01:02PM

Re: Purge the Nginx cache

kaushalshriyan April 22, 2022 01:32PM

Re: Purge the Nginx cache

Sergey A. Osokin April 22, 2022 01:42PM

Re: Purge the Nginx cache

kaushalshriyan April 22, 2022 01:56PM

Re: Purge the Nginx cache Attachments

kaushalshriyan April 26, 2022 02:02PM

Re: Purge the Nginx cache

kaushalshriyan April 26, 2022 02:28PM

Re: Purge the Nginx cache

Sergey A. Osokin April 26, 2022 04:44PM

Re: Purge the Nginx cache Attachments

kaushalshriyan April 28, 2022 03:30PM

Re: Purge the Nginx cache

kaushalshriyan April 29, 2022 02:20PM

Re: Purge the Nginx cache

kaushalshriyan May 02, 2022 03:10PM

Re: Purge the Nginx cache

Francis Daly May 03, 2022 04:30AM

Re: Purge the Nginx cache Attachments

kaushalshriyan May 03, 2022 06:34AM

Re: Purge the Nginx cache

Francis Daly May 03, 2022 08:02AM

Re: Purge the Nginx cache Attachments

kaushalshriyan May 03, 2022 12:22PM

Re: Purge the Nginx cache

Francis Daly May 04, 2022 09:10AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 90
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready