Home >Backend Development >PHP Tutorial >nginx + lua resource anti-leeching

nginx + lua resource anti-leeching

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 09:11:141420browse

Instructions for use

1. Install lua extension for nginx

2. Modify the nginx configuration file

  1. set $salt “cmstopSalt”; md5 keychain
  2. set $expire “ 2"; Expiration time
  3. set $timeType 'seconds'; The expiration time type seconds is seconds and its value is minutes

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';

}


5. PHP key generation rules and parameter settings

//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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn