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

Antonio P.P. Almeida appa at perusio.net
Tue Apr 3 10:18:00 UTC 2012


> 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



More information about the nginx mailing list