# What is the correct way to flush/delete proxy\_cache without restart nginx?

**URL:** <https://www.ruby-forum.com/t/what-is-the-correct-way-to-flush-delete-proxy-cache-without-restart-nginx/180455>\
**Category:** NGINX\
**Created:** [December 19, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/what-is-the-correct-way-to-flush-delete-proxy-cache-without-restart-nginx/180455 "2009-12-19T15:25:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 19, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/what-is-the-correct-way-to-flush-delete-proxy-cache-without-restart-nginx/180455/1 "2009-12-19T15:25:40Z")

</div>

what is the correct way to flush/delete proxy\_cache without restart  
nginx?

kill -HUP doesn’t seems to work.

I tried use script like  
find /data/nginx/proxy\_cache2 -type f -exec rm -f {};

but the file still there, it seems nginx have locked the cache files.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 19, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/what-is-the-correct-way-to-flush-delete-proxy-cache-without-restart-nginx/180455/2 "2009-12-19T15:25:40Z")

</div>

rm -rf /data/nginx/proxy\_cache2/\*

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 19, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/what-is-the-correct-way-to-flush-delete-proxy-cache-without-restart-nginx/180455/3 "2009-12-19T15:25:40Z")

</div>

As far as I know there is no official way to flush / empty cache.

You can either:  
a) purge whole cache using “rm -rf /data/nginx/proxy\_cache2” (this will  
somehow invalidate all cache files, because nginx won’t be able to open  
them  
anymore),  
b) purge selected pages using cache\_purge patch [1].

[1] [FRiCKLE Labs / nginx / cache\_purge](http://labs.frickle.com/nginx_cache_purge)

Best regards,  
Piotr S. \< removed\_email\_address@domain.invalid \>

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 19, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/what-is-the-correct-way-to-flush-delete-proxy-cache-without-restart-nginx/180455/4 "2009-12-19T15:25:43Z")

</div>

rm -rf /data/nginx/proxy\_cache2  
Doesn’t that will affect nginx keep creating the cache? I mean doesn’t  
that  
stop proxy cache working since directory doesn’t existed?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 22, 2009, 3:05pm UTC](https://www.ruby-forum.com/t/what-is-the-correct-way-to-flush-delete-proxy-cache-without-restart-nginx/180455/5 "2009-12-22T15:05:31Z")

</div>

> rm -rf /data/nginx/proxy\_cache2  
> Doesn’t that will affect nginx keep creating the cache? I mean doesn’t  
> that  
> stop proxy cache working since directory doesn’t existed?

No, it won’t, because nginx will re-create directory when needed. This  
could  
potentialy disrupt work of cache helpers (cache manager & cache loader),  
so  
just to be on the safe side you could run this instead:

# rm -rf /data/nginx/proxy\_cache2 && killall -HUP nginx

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 2, 2010, 10:22am UTC](https://www.ruby-forum.com/t/what-is-the-correct-way-to-flush-delete-proxy-cache-without-restart-nginx/180455/6 "2010-09-02T10:22:36Z")

</div>

Try to use my script on site:  
[http://linux-sysadmin.org/2010/08/nginx-invalidation-purging-content/](http://linux-sysadmin.org/2010/08/nginx-invalidation-purging-content/)

Posted at Nginx Forum:

> **[Re: what is the correct way to flush/delete proxy\_cache withoutrestartnginx?](https://forum.nginx.org/read.php?2,30833,126252#msg-126252)**
>
> what is the correct way to flush/delete proxy\_cache without restart nginx? kill -HUP doesn't seems to work. I tried use script like find /data/nginx/proxy\_cache2 -type f -exec rm -f {}\\; but the file still there, it seems nginx have locked the cache...

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 2, 2010, 10:34am UTC](https://www.ruby-forum.com/t/what-is-the-correct-way-to-flush-delete-proxy-cache-without-restart-nginx/180455/7 "2010-09-02T10:34:54Z")

</div>

If you want to clear the cache, you can do it like this:

[root@… ~]#cd {proxy\_cache\_path}  
[root@… ~]#find -type f -exec rm -f {} ;

If you want to clear a specified item, you can use this module:

> **[FRiCKLE Labs / nginx / ngx\_cache\_purge](http://labs.frickle.com/nginx_ngx_cache_purge/)**

On Thu, Sep 2, 2010 at 4:22 PM, Radek [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Try to use my script on site:  
> [http://linux-sysadmin.org/2010/08/nginx-invalidation-purging-content/](http://linux-sysadmin.org/2010/08/nginx-invalidation-purging-content/)
> 
> Posted at Nginx Forum:  
> [http://forum.nginx.org/read.php?2,30833,126252#msg-126252](http://forum.nginx.org/read.php?2,30833,126252#msg-126252)
