欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

nginx secure link防盗链 伪静态重写

shiping 的头像
下载 code.txt
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
location ~ \.mp4 {
		rewrite ^(.*)/(.*)/(.*)/media/(.+)\.mp4$ $1/media/$4.mp4?s=$2&e=$3 last;
		secure_link $arg_s,$arg_e;
		secure_link_md5 test$uri$arg_e;
		if ($secure_link = "") {
		    return 403;
		}
		if ($secure_link = "0") {
		    return 403;
		}
		mp4;
		mp4_buffer_size       5m;
		mp4_max_buffer_size   50m;
	}

php代码:

    展开/关闭下载 code.txt
 
1
2
3
4
5
6
7
8
9
10
11
$cdn = "http://www.test.com";
$path = "/media/000.mp4";
$secret = "test";
$expire = time() + 3600;  # Link 1 hours expire 1小时过期
$md5 = base64_encode(md5($secret . $path . $expire, true));
$md5 = strtr($md5, '+/', '-_');
$md5 = str_replace('=', '', $md5);
$url = $cdn.$path."?s=".$md5."&e=".$expire;
echo $url."<br>";
$seo = $cdn."/".$md5."/".$expire.$path;
echo $seo;

 

声明: 本文由( admin )原创编译,转载请保留链接: nginx secure link防盗链 伪静态重写

来自 http://www.xsdou.com/1742.html
普通分类: