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

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

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