nginx + lua 资源防盗链
2015-12-02 10:43
405 查看
使用说明
nginx安装lua扩展
修改配置nginx配置文件
set salt“cmstopSalt”;md5的密钥串setexpire “2”; 过期时间
set $timeType ‘seconds’; 过期时间类型 seconds为秒 期它值为分钟
以下代码保存为lua文件
项目的nginx配置文件中增加以下代码
//nginx中定义的值 如:cmstopSalt
index.m3u8?key=< ?php echo md5(‘cmstopSalt’.time)?>&time=<?php echotime;?>
“`
nginx安装lua扩展
修改配置nginx配置文件
set salt“cmstopSalt”;md5的密钥串setexpire “2”; 过期时间
set $timeType ‘seconds’; 过期时间类型 seconds为秒 期它值为分钟
以下代码保存为lua文件
--获取md5值 function getMd5(time) return ngx.md5(ngx.var.salt .. time) end --获取参数 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']) --获取允许的时间范围 local ur = 0; local interval = 1; if ngx.var.timeType ~= 'seconds' then interval = 60; end --验证key是否合法 是否过期 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 if 0 == ur then ngx.exit(403) end
项目的nginx配置文件中增加以下代码
location ~ \.m3u8$ { rewrite_by_lua_file 'lua文件地址'; } ``` 5. PHP生成密钥规则与参数设置
//nginx中定义的值 如:cmstopSalt
index.m3u8?key=< ?php echo md5(‘cmstopSalt’.time)?>&time=<?php echotime;?>
“`
相关文章推荐
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- Nginx 学习笔记(一)
- 网站502与504错误分析
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 详解Lua中的表的概念及其相关操作方法
- C#、ASP.NET通用扩展工具类之TypeParse
- Lua编程示例(二):面向对象、metatable对表进行扩展
- Windows Powershell扩展类型系统
- 把Lua编译进nginx步骤方法
- Lua脚本自动生成APK包