默認沒有安裝Secure Link - Nginx 在原有的基礎上添加

--with-http_secure_link_module

示例

./configure --user=www --group=www --prefix=/usr/local/nginx 
--with-http_stub_status_module --with-http_ssl_module 
--with-http_gzip_static_module --with-http_mp4_module 
--with-http_flv_module --with-http_secure_link_module

普通加密連接如下

http://m.nn5.org/media/000.mp4?s=oJ-RnINtL028POIlzeLXGA&e=1381153610

這類鏈接下載是可以的可是大部分視頻播放器并無法讀取此類型需要美化下效果如下

http://m.nn5.org/oJ-RnINtL028POIlzeLXGA/1381153610/media/000.mp4

編輯nginx.conf 在server加入

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; #test為密碼定期更換
        if ($secure_link = "") {
            return 403;
        }
        if ($secure_link = "0") {
            return 403;
        }
        mp4;
        limit_rate_after 3048k; 
        limit_rate       120k; 
}

根據自己情況適當修改
php測試代碼

$cdn = "http://www.nn5.org";
$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;