nginx防盜鏈配置
location ~.*\.(gif|jpg|png|flv|swf|rar|zip)${
valid referers none blocked test.com *.test.com;
if ($invalid_referer)
{
#return 403;
rewrite ^/ http://www.test.com/403.jpg;
}
}
傳統防盜鏈遇到的問題(偽造Referer)
可以使用加密簽名解決
location ~.*\.(gif|jpg|png|flv|swf|rar|zip)${
accesskey on;
accesskey_hashmethod md5;
accesskey_arg sign;
accesskey_signature "jason$remote_addr";
expires 30d;
}
<?php
$sign = md5('jason'.$_SERVER['REMOTE_ADDR]);
echo '<img src="./logo_new.png?sign='. $sign.'">';
本作品採用《CC 協議》,轉載必須註明作者和本文連結