Nginx之禁止访问修改时间2022年以前的文件

location ~ .*\.(html|css|jpg|gif|js|png|htm)?$
{
access_by_lua_block {
-- 获取请求的文件名称
local filename = ngx.var.request_filename

-- 获取该文件的修改时间
local command = "stat -c %Y " .. filename
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()

-- 解析命令的执行结果,获取文件的修改时间
local mtime = tonumber(result)

-- 判断修改时间与自己指定的时间大小
local cutoff_time = os.time{year=2022, month=1, day=1, hour=0, min=0, sec=0}
if mtime < cutoff_time then
ngx.status = 403
ngx.exit(ngx.HTTP_FORBIDDEN)
end
}

expires 24h;
}

posted @ 2024-04-26 11:06  奋斗史  阅读(10)  评论(0)    收藏  举报