Instructions for use
1. Nginx installation of LUA extensions
2. Modify the configuration Nginx configuration file
- Set $salt "Cmstopsalt"; MD5 key string
- Set $expire "2"; Expiry time
- Set $timeType ' seconds '; Expiration time type seconds to seconds it's value is minutes
3. Save the following code as a LUA file
--Get MD5 value
function GetMd5 (time)
Return Ngx.md5 (Ngx.var.salt. Time)
End
--Get parameters
Local args = Nil
If "GET" = = Ngx.var.request_method Then
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 that key is valid or not expired
If time ~= nil and key ~= nil and string.len (key) = = + GETMD5 (time) = = key and Time + Tonumber (ngx.var.expire) * inte Rval >= Tonumber (Os.time ()) Then
ur = 1;
End
if 0 = = ur Then
Ngx.exit (403)
End
4. Add the following code to the Nginx configuration file for the project
Location ~ \.m3u8$ {
Rewrite_by_lua_file ' Lua file address ';
}
5. PHP generated key rules and parameter settings
The values defined in Nginx are as follows: Cmstopsalt
index.m3u8?key= &time=
The above describes the Nginx + LUA resource anti-theft chain, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.