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;