nginx添加key訪問限制,并且對鏈接加超時失效策略
實現key訪問限制,nginx通過accessKey來實現。
具體參考:
實現鏈接的超時失效策略,nginx通過Secure Link來實現。
具體參考:
由于網上說的實現代碼都是基于PHP的,所以在這我用JAVA實現了下。
具體參考:
http://www.lamppr.com/node/620
實現鏈接的超時失效策略,nginx通過Secure Link來實現。
具體參考:
http://www.xsdou.com/1734.html
由于網上說的實現代碼都是基于PHP的,所以在這我用JAVA實現了下。
<?php
$secret = 'password'; # 密鑰
$path = '/download/she.flv'; # 下載文件
$ipkey= md5("password".$_SERVER['REMOTE_ADDR']); #加密IP
# 下載到期時間,time是當前時間,300表示300秒,也就是說從現在到300秒之內文件不過期
$expire = time()+300;
# 用文件路徑、密鑰、過期時間生成加密串
$md5 = base64_encode(md5($secret . $path . $expire, true));
$md5 = strtr($md5, '+/', '-_');
$md5 = str_replace('=', '', $md5);
# 加密后的下載地址
echo '<a href=http://s1.xsdou.com/download/she.flv?key='.$ipkey.'&st='.$md5.'&e='.$expire.'>she.flv</a>';
echo '<br>http://s1.xsdou.com/download/she.flv?key='.$ipkey.'&st='.$md5.'&e='.$expire;
?>
$secret = 'password'; # 密鑰
$path = '/download/she.flv'; # 下載文件
$ipkey= md5("password".$_SERVER['REMOTE_ADDR']); #加密IP
# 下載到期時間,time是當前時間,300表示300秒,也就是說從現在到300秒之內文件不過期
$expire = time()+300;
# 用文件路徑、密鑰、過期時間生成加密串
$md5 = base64_encode(md5($secret . $path . $expire, true));
$md5 = strtr($md5, '+/', '-_');
$md5 = str_replace('=', '', $md5);
# 加密后的下載地址
echo '<a href=http://s1.xsdou.com/download/she.flv?key='.$ipkey.'&st='.$md5.'&e='.$expire.'>she.flv</a>';
echo '<br>http://s1.xsdou.com/download/she.flv?key='.$ipkey.'&st='.$md5.'&e='.$expire;
?>
public static void main(String[] args) {
String secret = "password";
String path = "/mp4files/1162000000062C6B/221.194.64.19/2/45a594b6938698f63b5771c12ff5b912.mp4";
String expire = String.valueOf(System.currentTimeMillis() / 1000 + 600);
String remoteIp = "192.168.1.145";
String ipkey = DigestUtils.md5Hex(secret + remoteIp);
String st = new sun.misc.BASE64Encoder().encode(DigestUtils.md5(secret + path + expire)).replaceAll("\\+/", "-_").replaceAll("=", "");
System.out.println("ipkey: " + ipkey);
System.out.println("st: " + st);
System.out.println("e: " + expire);
}
String secret = "password";
String path = "/mp4files/1162000000062C6B/221.194.64.19/2/45a594b6938698f63b5771c12ff5b912.mp4";
String expire = String.valueOf(System.currentTimeMillis() / 1000 + 600);
String remoteIp = "192.168.1.145";
String ipkey = DigestUtils.md5Hex(secret + remoteIp);
String st = new sun.misc.BASE64Encoder().encode(DigestUtils.md5(secret + path + expire)).replaceAll("\\+/", "-_").replaceAll("=", "");
System.out.println("ipkey: " + ipkey);
System.out.println("st: " + st);
System.out.println("e: " + expire);
}
posted on 2013-12-24 10:20 小一敗涂地 閱讀(789) 評論(0) 編輯 收藏 所屬分類: nginx、squid、haproxy、varnish等