首页 > Linux系统 > system > nginx secure link防盗链 伪静态重写
2013
12-05

nginx secure link防盗链 伪静态重写

nginx.conf配置文件

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代码:

$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."
"; $seo = $cdn."/".$md5."/".$expire.$path; echo $seo;
最后编辑:
作者:admin
捐 赠如果您觉得这篇文章有用处,请支持作者!鼓励作者写出更好更多的文章!

留下一个回复