# Possible trigger actio of clearing cache within location /clearcache { }

**URL:** <https://www.ruby-forum.com/t/possible-trigger-actio-of-clearing-cache-within-location-clearcache/218515>\
**Category:** NGINX\
**Created:** [April 3, 2012, 6:56am UTC](https://www.ruby-forum.com/t/possible-trigger-actio-of-clearing-cache-within-location-clearcache/218515 "2012-04-03T06:56:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [April 3, 2012, 6:56am UTC](https://www.ruby-forum.com/t/possible-trigger-actio-of-clearing-cache-within-location-clearcache/218515/1 "2012-04-03T06:56:59Z")

</div>

Is it possible to somehow (and without installing PHP) invoking the  
action of clearing the nginx cache (rm -fr /var/www/cache/\*) by simply  
visiting a location {} of the server {} ? Obviously I would allow only  
specific IPs to that location.

Regards,  
Mike

---

<div class="post-metadata">

**Author:** ![Micheal\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac8455/32.png) [@Micheal\_W](https://www.ruby-forum.com/u/Micheal_W)\
**Post date:** [April 3, 2012, 12:18pm UTC](https://www.ruby-forum.com/t/possible-trigger-actio-of-clearing-cache-within-location-clearcache/218515/2 "2012-04-03T12:18:20Z")

</div>

> Is it possible to somehow (and without installing PHP) invoking the action  
> of clearing the nginx cache (rm -fr /var/www/cache/\*) by simply visiting a  
> location {} of the server {} ? Obviously I would allow only specific IPs  
> to that location.

Yes with Lua. Try:

location = /clearcache {

```
allow 127.0.0.1;
allow ::1;
deny all;
content_by_lua 'local status = os.execute("rm -fr /var/www/cache/*")
                if status == 0 then
                   ngx.say("Cache cleared")
                else
                   ngx.say("Cache not cleared")
                end';

```

}

–appa
