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;
}
一往无前虎山行,拨开云雾见光明

浙公网安备 33010602011771号