Nginx的防盗链设置

发现最近主机的流量猛增,想到太多的下载和图片,还是决定部署下nginx的防盗链。

nginx的防盗链,和rewrite一样,写在配置的conf文件下。

一般的防盗链格式为:
location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv)$ {
valid_referers none blocked *.ballpure.com *.goalpure.com *.xpbeta.com;
if ($invalid_referer) {
#rewrite ^/ http://www.ballpure.com/403.html;
return 403;
}
}

第一行:wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv
表示对这些后缀的文件实行防盗链
第二行:*.ballpure.com *.goalpure.com *.xpbeta.com,表示允许这类网站的任何二级域名读取。
if{}里面内容的意思是,如果来路不是指定来路就跳转到错误页面,当然直接返回403也是可以的。

This entry was posted in Nginx and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>