Home >Backend Development >PHP Tutorial >nginx + lua resource anti-leeching
Instructions for use
1. Install lua extension for nginx
2. Modify the nginx configuration file
3. The following code is saved as a lua file
--Get the md5 value
function getMd5(time)
Return ngx.md5(ngx.var.salt .. time)
end
--Get parameters
local args = nil
"IF "get" == ngx.var.request_method the
args = ngx.req.get_uri_args ()
End
local key = args ['key']
Local time = tonumber(args['time'])
--Get the allowed time range
local ur = 0;
local interval = 1;
if ngx.var.timeType ~ = 'seconds' then
interval = 60;
end
--Verify whether the key is legal and expired
if time ~= nil and key ~= nil and string.len(key ) == 32 and getMd5(time) == key and time + tonumber(ngx.var.expire) * interval >= tonumber(os.time()) then
ur = 1;
end � .m3u8$ {
rewrite_by_lua_file 'lua file address';
}
//The value defined in nginx is such as: cmstop Salt
index.m3u8?key=&time=
The above introduces nginx + lua resource hotlink prevention, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.