教你如何实现Nginx防盗链

一、ngx_http_referer_module(阻挡来源非法的域名请求),配置如下:

location ~.*. (gif|jpg|png|flv|swf|rar|zip)$
{
 valid_referers none blocked test.com *.test.com;
 if($valid_referer)
 {
 #return 403;
 rewrite ^/ http://www.test.com/403.jpg;
 }
}

二、HttpAccessKeyMoudule,配置如下:

location ~.*. (gif|jpg|png|flv|swf|rar|zip)$
{
 accesskey on;
 accesskey_hashmethod md5;
 accesskey_arg "key";
 accesskey_signature "mypass$remote_addr";
}
胜象大百科