Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从nginx内部使用lua删除缓存文件_Nginx_Lua - Fatal编程技术网

从nginx内部使用lua删除缓存文件

从nginx内部使用lua删除缓存文件,nginx,lua,Nginx,Lua,我让nginx运行,它将缓存文件保存到本地磁盘。我必须不时手动清除缓存。我考虑添加一个额外的位置,比如/clear\u cache,在这里我直接用Lua删除本地文件,因为它可以嵌入nginx中。 我做了一些研究,发现了像是rewrite\u by_lua或者content\u by_lua。是否可以使用Lua访问/修改底层fs,或者是否受限制?是的,您可以删除文件: location /clear_cache { content_by_lua_block { //file

我让nginx运行,它将缓存文件保存到本地磁盘。我必须不时手动清除缓存。我考虑添加一个额外的位置,比如
/clear\u cache
,在这里我直接用Lua删除本地文件,因为它可以嵌入nginx中。
我做了一些研究,发现了像是
rewrite\u by_lua
或者
content\u by_lua
。是否可以使用Lua访问/修改底层fs,或者是否受限制?

是的,您可以删除文件:

location /clear_cache {
    content_by_lua_block {
        //file creation
        local f = assert(io.open("/newFile.txt", 'wb')) -- open in "binary" mode
        f:write(body)
        f:close()

        //Remove file
        os.remove("/newFile.txt")
    }
}