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 在当前月底使静态HTML文件过期_Nginx_Lua - Fatal编程技术网

Nginx 在当前月底使静态HTML文件过期

Nginx 在当前月底使静态HTML文件过期,nginx,lua,Nginx,Lua,我有几个静态HTML文件,它们是在每个月的第一天生成的,并且在同一个月结束前都很好。我希望在月底到期但不知道如何告诉nginx这样做 我可以使用Lua或其他语言在配置文件中计算该日期吗?或者这会占用太多的计算能力吗 目前,我正在使用此配置使其在7天后过期。要在当月最后一天23:59时到期,我必须更改哪些内容 location ~* \.(html|HTML)$ { gzip_static on; add_header Cache-Control public; expires 7d

我有几个静态HTML文件,它们是在每个月的第一天生成的,并且在同一个月结束前都很好。我希望
在月底到期
但不知道如何告诉
nginx
这样做

我可以使用Lua或其他语言在配置文件中计算该日期吗?或者这会占用太多的计算能力吗

目前,我正在使用此配置使其在7天后过期。要在当月最后一天23:59时到期,我必须更改哪些内容

location ~* \.(html|HTML)$ {
  gzip_static on;
  add_header  Cache-Control public;
  expires 7d;
}

在lua中,您可以简单地编写一个函数

-- day is the day of the month as a number
-- file can be 1 filename or a table of several filenames
function expire(file, day, time_)
    day = day or 1 -- day's default value incase it isn't set 
    -- get the current day of the month, convert it to a number and compare it to day
    -- get the current hour and minute and compare it to time_
    if tonumber(os.date("%d")) == day and os.date("%H:%M") == time_ then
        -- see if file is a table
        if type(file) == 'table' then
            -- if it is cycle through the table for the file names
            for _, filename in pairs(file) do
                -- make sure we are dealing with a string
                if type(filename) == 'string' then
                    -- delete the file
                    os.remove(filename)
                end
            end
        else
            -- make sure file is a string
            if type(file) == 'string' then
                -- delete the file
                os.remove(file)
            end
        end
    end
end

-- calling the function
expire("somefile.txt", 31, "23:59")
有关操作系统日期的更多信息,请查看