Nginx 防盗链
2011年6月7日
| 发布: admin
点击图片查看更多内容
1. 针对不同的文件类型
#Preventing hot linking of images and other file types
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip)$ {
valid_referers none blocked server_names *.xtgly.com xtgly.com http://localhost baidu.com;
if ($invalid_referer) {
rewrite ^/ http://www.xtgly.com/images/default/logo.gif;
# return 403;
}
}
2. 针对不同的目录
location /img/ {
root /data/www/wwwroot/bbs/img/;
valid_referers none blocked server_names *.xtgly.com http://localhost baidu.com;
if ($invalid_referer) {
rewrite ^/ http://www.xtgly.com/images/default/logo.gif;
#return 403;
}
}
3. 同实现防盗链和expires的方法
#Preventing hot linking of images and other file types
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip)$ {
valid_referers none blocked server_names *.xtgly.com xtgly.com http://localhost ;
if ($invalid_referer) {
rewrite ^/ http://www.xtgly.com/images/default/logo.gif;
}
access_log off;
root /data/www/wwwroot/bbs;
expires 1d;
break;
}
请对我们的文章进行评论
标签: nginx
发表评论
